New Support for Microcontainer based tests
adrian.brock Oct 4, 2005 5:45 PMI've committed a prototype of using the Microcontainer from testcases.
You trivially extend the base test and use a suite() to bootstrap the test's
microcontainer xml config.
The xml config must be in the classpath and have a similar name to the testcase.
e.g.
org.jboss.test.junit.test.JUnitTestCase.java
/* * JBoss, Home of Professional Open Source * * Distributable under LGPL license. * See terms of license at gnu.org. */ package org.jboss.test.junit.test; import junit.framework.Test; import org.jboss.test.kernel.junit.MicrocontainerTest; /** * A JUnitTestCase. * * @author <a href="adrian@jboss.com">Adrian Brock</a> * @version $Revision: 1.1 $ */ public class JUnitTestCase extends MicrocontainerTest { /** * Bootstrap the test * * @return the test */ public static Test suite() { return suite(JUnitTestCase.class); } /** * Create a new JUnitTestCase. * * @param name the test name */ public JUnitTestCase(String name) { super(name); } public void testOne() throws Exception { System.out.println(getBean("TheBean")); } public void testTwo() throws Exception { System.out.println(getBean("TheBean")); } }
org.jboss.test.junit.test.JUnitTestCase.xml
<?xml version="1.0" encoding="UTF-8"?> <deployment xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="urn:jboss:bean-deployer bean-deployer_1_0.xsd" xmlns="urn:jboss:bean-deployer"> <bean name="TheBean" class="javax.naming.InitialContext"/> </deployment>
Produces the following output:
0 DEBUG [JUnitTestCase] ==== setUp org.jboss.test.junit.test.JUnitTestCase ==== 25 DEBUG [KernelFactory] Starting JBoss Kernel construction... 510 DEBUG [KernelFactory] Completed JBoss Kernel construction. Duration: 485 milliseconds 1585 WARN [XsdBinder] NOT HANDLED WILDCARD IN GLOBAL MODEL GROUP 1976 DEBUG [JUnitTestCase] Deploying file:/home/adrian/jboss-head/workspace/kernel/src/resources/org/jboss/test/junit/test/JUnitTestCase.xml 2111 DEBUG [JUnitTestCase] Deployed file:/home/adrian/jboss-head/workspace/kernel/src/resources/org/jboss/test/junit/test/JUnitTestCase.xml 2114 DEBUG [JUnitTestCase] ==== Starting testOne ==== javax.naming.InitialContext@f07355 2115 DEBUG [JUnitTestCase] ==== Stopping testOne ==== 2115 DEBUG [JUnitTestCase] ==== Starting testTwo ==== javax.naming.InitialContext@f07355 2116 DEBUG [JUnitTestCase] ==== Stopping testTwo ==== 2116 DEBUG [JUnitTestCase] ==== tearDown org.jboss.test.junit.test.JUnitTestCase ==== 2116 DEBUG [JUnitTestCase] Undeploying file:/home/adrian/jboss-head/workspace/kernel/src/resources/org/jboss/test/junit/test/JUnitTestCase.xml 2117 DEBUG [JUnitTestCase] Undeployed file:/home/adrian/jboss-head/workspace/kernel/src/resources/org/jboss/test/junit/test/JUnitTestCase.xml