简体   繁体   中英

unit testing - advice needed

i have spring project that consists of a parent and few child projects. the build is maven-based and the continous integration server is hudson.

i need to choose the way the unit tests will run. currently, there are several good and also quite few garbage junit tests. i preffer not to mess with the test packages of the child projects since it would be time-consuming, i am not familiar with all the junits and the last but not least: i'm lazy.

my questions are:

  1. should i use maven-surefire-plugin and do a heavy cleanup in the test package?
  2. is it any way to tell hudson (not in pom.xml of the project being built) to run specific unit tests and ignore others?
  3. should I create some other build - (ant?) and use it for running unit tests on hudson?
  4. are there any other options good options in the market i am not aware of?

any piece of advice would be appreciated.

aviad

  1. should i use maven-surefire-plugin and do a heavy cleanup in the test package?
  2. is it any way to tell hudson (not in pom.xml of the project being built) to run specific unit tests and ignore others?

If you just want to run unit tests in a single-module project, you can do

mvn test

That will run all maven lifecycle phases up to test , including compile and test-compile (as you can see in built-in lifecycle bindings , the surefire:test goal is executed in phase test ). Now if you want to restrict the unit tests that are executed, you can configure the surefire:test plugin execution with the test parameter:

mvn test -Dtest=Funky*Test

(This will execute all test classes that start with Funky and end with Test )


Unfortunately, the command line configuration is limited, if you want multiple includes and excludes you will have to do some XML configuration. I'd suggest to use a dedicated profile for hudson:

<profiles>
    <profile>
        <id>hudson</id>
        <build>
            <plugins>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-surefire-plugin</artifactId>
                    <version>2.6</version>
                    <configuration>
                        <includes>
                            <include>**/TestA.java</include>
                            <include>**/Funky*Test.java</include>
                            <include>**/Test**.java</include>
                        </includes>
                        <excludes>
                            <!-- overrides above include -->
                            <exclude>**/TestButNotMe.java</exclude>
                        </excludes>
                    </configuration>
                </plugin>
            </plugins>
        </build>
    </profile>
</profiles>

Now you can let your hudson call maven like this:

mvn -Phudson test

1) should i use maven-surefire-plugin and do a heavy cleanup in the test package?

yes

2) is it any way to tell hudson (not in pom.xml of the project being built) to run specific unit tests and ignore others?

I don't know any if you use JUnit. But you could check the "hidden" features of version 4.7, 4.6, 4.5... (there are many, you can found it in the release notes). If there is nothing what you need, then you could program it by yourselfe. (checking for a system property and skip the test).

3) should I create some other build - (ant?) and use it for running unit tests on hudson?

This would be the same like sprecifiying it in the pom. But in my personal opining mixing Ant and Maven is one of the uggliest thing you can do.

4) are there any other options good options in the market i am not aware of?

Have a look at TestNG .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM