Junit test not found system property when run from

2019-08-06 09:11发布

问题:

I tried to implement a simple CRUD application and tests with Arquillian based on this tutorial: Java EE with Wildfly and Maven. But when I try to run the tests from Eclipse it throws: org.jboss.arquillian.container.spi.ConfigurationException: jbossHome 'null' must exist. But from command line, use mvn clean install, the tests runs good.

My pom.xml build part.

<build>
    <finalName>${project.artifactId}</finalName>
    <plugins>
        <plugin>
            <artifactId>maven-dependency-plugin</artifactId>
            <executions>
                <execution>
                    <id>unpack</id>
                    <phase>process-test-classes</phase>
                    <goals>
                        <goal>unpack</goal>
                    </goals>
                    <configuration>
                        <artifactItems>
                            <artifactItem>
                                <groupId>org.wildfly</groupId>
                                <artifactId>wildfly-dist</artifactId>
                                <version>8.2.0.Final</version>
                                <type>zip</type>
                                <overWrite>false</overWrite>
                                <outputDirectory>target</outputDirectory>
                            </artifactItem>
                        </artifactItems>
                    </configuration>
                </execution>
            </executions>
        </plugin>

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <version>2.17</version>
            <configuration>
                <configuration>
                    <reuseForks>false</reuseForks>
                    <forkCount>1</forkCount>
                </configuration>
                <systemPropertyVariables>
                    <java.util.logging.manager>org.jboss.logmanager.LogManager</java.util.logging.manager>
                    <jboss.home>${project.basedir}/target/wildfly-8.2.0.Final</jboss.home>
                    <module.path>${project.basedir}/target/wildfly-8.2.0.Final/modules</module.path>
                </systemPropertyVariables>
                <redirectTestOutputToFile>false</redirectTestOutputToFile>
            </configuration>
        </plugin>
        <plugin>
            <artifactId>maven-war-plugin</artifactId>
            <version>${version.war.plugin}</version>
            <configuration>
                <failOnMissingWebXml>false</failOnMissingWebXml>
            </configuration>
        </plugin>
    </plugins>
</build>

If I run tests with maven the jboss.home system varibale was set by the surefire plugin, but I can't understand why eclipse can't use this variables from pom.xml.

I looking for a clear solution for this problem. (If it's possible I want to use Eclipse to read this configuration from pom.xml not configure Eclipse run settings. )

Sorry for the grammatical errors, I use my english knowledge rarely.

回答1:

AFAIK the JUnit Eclipse runner has nothing to do with Maven which is why it can't find your environment variable.

However...so long as you imported your project as a maven project, Eclipse has the m2e plugins and your test class has *Test in the name you should be able to run your JUnit tests by doing:

Alt-Click SomeNameTest.java Run as -> Maven Test


回答2:

I solve this problem, using remote wildfly container under development, and testing. It runs tests fast, and in eclipse, click Run as Junit test case, so I can run the test what I want.