With the installment of AS 7 we have a perfect runtime implementation for a modular environment in the form of jboss-modules.


Now I also want it to be usable from within an IDE (in this case Intellij) and Maven (our current build tool). So I figured that through the use of a JUnit Runner I could setup a moduler enviroment (similar to Arquillian).


First you'll have to pickup a piece of experimental code I call jboss-modules-junit at https://github.com/wolfc/jboss-modules-junit.


Now you can start to run your test case within a modular environment simply by saying @RunWith(Modules.class).

public class MyTestCase {


By default Modules will take the test class name as the module name. This can be overriden with @ModuleName.


First you'll need a module.xml file to represent your test module. By default the modules runner will look it up on your class path entry of your test class.

<?xml version="1.0" encoding="UTF-8"?><module xmlns="urn:jboss:module:1.0" name="org.jboss.modules.junit.SimpleTestCase">
        <!-- a trick to add the original class path entry -->
        <resource-root path="../../../../../.."/>

        <module name="junit"/>
        <module name="org.jboss.logmanager"/>



Because you share JUnit with whoever is running the test (IDE or build tool) you need to define a junit module as such. Currently this is a manual requirement.

<?xml version="1.0" encoding="UTF-8"?><module xmlns="urn:jboss:module:1.0" name="junit">
        <module name="system" export="false">
                    <path name="junit/framework"/>
                    <path name="org/junit"/>



So I bring it all together on our main project, AS 7, https://github.com/wolfc/jboss-as/blob/JBAS-9020-test/testsuite/smoke/src/test/java/org/jboss/as/test/surefire/servermodule/ServerInModuleDeploymentTestCase.java. You can try it for yourself by using https://github.com/wolfc/jboss-as/tree/JBAS-9020-test. Additional VM parameters are required though:

  • -Djboss.home.dir=/home/carlo/work/jboss-as/build/target/jboss-7.0.0.Beta4-SNAPSHOT (mandatory)
  • -Dmodule.path=target/test-classes/modules:/home/carlo/work/jboss-as/build/target/jboss-7.0.0.Beta4-SNAPSHOT/modules (override module repos)
  • -Djava.util.logging.manager=org.jboss.logmanager.LogManager (because of Intellij bug, see below)
  • -Djboss.embedded.root=target/temp-config (to instruct AS Embedded to make a copy)


Some caveats though:

  1. Intellij contains a bug which initializes a JUnit test case class too soon (http://youtrack.jetbrains.net/issue/IDEA-68658 fixed in 108.13)
  2. Maven and Intellij disagree in which directory to start the test, so you have to explicitly specify $MODULE_DIR$ as the Working directory in the Run Configuration.