1. mvn test
可以指定运行某特定类中的测试用例
mvn test -Dtest=test_classname
例子:
$ mvn test -Dtest=StringUtilTest [INFO] Scanning for projects... [INFO] [INFO] ------------------------------------------------------------------------ [INFO] Building Study 0.0.2 [INFO] ------------------------------------------------------------------------ [INFO] [INFO] --- maven-resources-plugin:2.4.3:resources (default-resources) @ Study --- [INFO] Using 'UTF-8' encoding to copy filtered resources. [INFO] skip non existing resourceDirectory C:\Documents and Settings\test\Documents\workspace-sts-2.9.2.RELEASE\Study\src\main\resources [INFO] [INFO] --- maven-compiler-plugin:2.3.2:compile (default-compile) @ Study --- [INFO] Nothing to compile - all classes are up to date [INFO] [INFO] --- maven-resources-plugin:2.4.3:testResources (default-testResources) @ Study --- [INFO] Using 'UTF-8' encoding to copy filtered resources. [INFO] skip non existing resourceDirectory C:\Documents and Settings\test\Documents\workspace-sts-2.9.2.RELEASE\Study\src\test\resources [INFO] [INFO] --- maven-compiler-plugin:2.3.2:testCompile (default-testCompile) @ Study --- [INFO] Nothing to compile - all classes are up to date [INFO] [INFO] --- maven-surefire-plugin:2.7.2:test (default-test) @ Study --- [INFO] Surefire report directory: C:\Documents and Settings\test\Documents\workspace-sts-2.9.2.RELEASE\Study\target\surefire-reports ------------------------------------------------------- T E S T S ------------------------------------------------------- Running com.boco.zhjk.Study.StringUtilTest ============================== print header: ================================================== %%%%%%%%%%%%%%% Customised Header %%%%%%%%%%%%%%%% ================================================== 00000034 Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.062 sec Results : Tests run: 1, Failures: 0, Errors: 0, Skipped: 0
也可以使用模糊匹配进行测试
mvn test -Dtest=*Test
2. mvn package
可以传入参数指定跳过Test阶段
mvn package -DskipTests
3. mvn cobertura:cobertura
查看单元测试覆盖率报告
运行这条指令后,在target文件夹下出现了一个site目录,下面是一个静态站点,里面就是单元测试的覆盖率报告