我有一个maven程序,它编译得很好。当我运行mvn测试时
它不会运行任何测试(在测试标题下显示没有要运行的测试。
)
我用一个超级简单的设置重新创建了这个问题,我将在下面介绍这个设置以及使用-X
运行时的输出
单元测试在eclipse中运行良好(使用默认的junit包,以及我包含maven下载的junit.jar)。另外,mvntest compile
正确地创建了测试类下的类。我在OSX 10.6.7上运行它,使用Maven 3.0.2和java 1.6.0_24
以下是目录结构:
/my_program/pom.xml
/my_程序/src/main/java/ClassUnderTest.java
/my_program/src/test/java/classundertests.java
pom.xml:
<;?xml version=“1.0”encoding=“UTF-8”?>;
<;项目xmlns=”http://maven.apache.org/POM/4.0.0“xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance“xsi:schemaLocation=”http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd“>;
<;模型版本>;4.0.0</模型版本>;
<;groupId>;我的团队</groupId>;
<;artifactId>;我的大学计划</artifactId>;
<;包装>;jar</包装>;
<;版本>;1.0-快照</版本>;
<;名称>;我的计划</名称>;
<;依赖关系>;
<;依赖性>;
<;groupId>;朱尼特</groupId>;
<;artifactId>;朱尼特</artifactId>;
<;版本>;4.8.1</版本>;
<;范围>;测试</范围>;
</依赖性>;
</依赖关系>;
<;构建>;
<;插件>;
<;插件>;
<;groupId>;org.apache.maven.plugins</groupId>;
<;artifactId>;maven编译器插件</artifactId>;
<;配置>;
<;来源>;1.5</来源>;
<;目标>;1.5</目标>;
</配置>;
</插件>;
</插件>;
</构建>;
</项目>;
ClassUnderTest.java:
测试中的公共类{
公共int函数测试(int n){
返回n;
}
}
classundertests.java:
导入org.junit.Assert;
导入org.junit.Before;
导入org.junit.Test;
测试下的公共类类{
被测私密类o;
@以前
公共作废设置(){
o=新类未测试();
}
@试验
test_testCase1()下的public void testfunction{
Assert.assertEquals(1,o.functionUnderTest(1));
}
@试验
test_testCase2()下的public void testfunction{
Assert.assertEquals(2,o.functionUnderTest(2));
}
}
mvn-X测试结束:
[DEBUG]配置mojo org.apache.maven.plugins:maven surefire插件:2.7.1:从插件领域ClassRealm进行测试[plugin>;org.apache.maven.plugins:maven surefire插件:2.7.1,父级:[email protected]]
[调试]使用基本配置程序配置mojo'org.apache.maven.plugins:maven surefire plugin:2.7.1:test-->;
[DEBUG](s)basedir=/Users/aron/Programs/my_program
[DEBUG](s)childDelegation=false
[DEBUG](s)classesDirectory=/Users/aaron/Programs/my_program/target/classes
[DEBUG](s)disableXmlReport=false
[DEBUG](s)enableAssertions=true
[调试](s)forkMode=一次
[DEBUG](s)junitarifactname=junit:junit
[DEBUG](s)localRepository=id:local
网址:file:///Users/aaron/.m2/repository/
布局:无
[DEBUG](f)parallelMavenExecution=false
[调试](s)pluginArtifactMap={org.apache.maven.plugins:maven-surefire-plugin=org.apache.maven.plugins:maven-surefire-plugin:2.7.1:,org.apache.maven.surefire:surefire-booter=org.apache.maven.surefire:surefire-api=org.apache.maven.surefire:surefire-api:jar:2.7.1:compile,org.apache.mavenurefire common=org.apache.maven.surefire:maven-surefire-common:jar:2.7.1:compile,org.apache.maven.shared:maven-common-artifact-filters=org.apache.maven.shared:maven-common-artifact-filters:jar:1.3:compile,org.codehaus.plexus:plexus-utils=org.codehaus.plexus:plexus-utils:plexus-utils:jar:2.0.5:compile,junit:junit:junit:junit:junit:junitreporting:maven reporting api=org.apache.maven.reporting:maven reporting api:jar:2.0.9:compile}
[调试](s)printSummary=true
[DEBUG](s)project=MavenProject:my_group:my_program:[email protected]/Users/aron/Programs/my_program/pom.xml
[DEBUG](s)projectArtifactMap={junit:junit=junit:junit:jar:4.8.1:test}
[DEBUG](s)RedirectTestOutputOfile=false
[DEBUG](s)remoteRepositories=[id:central
网址:http://repo1.maven.org/maven2
布局:默认值
快照:[已启用=>;错误,更新=>;每日]
发布:[已启用=>;真,更新=>;从不]
]
[调试](s)报告格式=简短
[调试](s)报告目录=/Users/aaron/Programs/my_program/target/surefire报告
[DEBUG](s)session=org.apache.maven.execution。[email protected]
[DEBUG](s)skip=false
[DEBUG](s)skipTests=false
[DEBUG](s)testClassesDirectory=/Users/aron/Programs/my_program/target/testclasses
[DEBUG](s)testFailureIgnore=false
[DEBUG](s)testNGArtifactName=org.testng:testng
[DEBUG](s)testSourceDirectory=/Users/alaron/Programs/my_program/src/test/java
[DEBUG](s)trimStackTrace=true
[DEBUG](s)useFile=true
[DEBUG](s)UseManistOnlyJar=true
[DEBUG](s)workingDirectory=/Users/aron/Programs/my_program
[调试]--结束配置--
[信息]Surefire报告目录:/Users/aaron/Programs/my_program/target/Surefire报告
[DEBUG]设置系统属性[user.dir]=[/Users/alaron/Programs/my_program]
[DEBUG]设置系统属性[localRepository]=[/Users/aaron/.m2/repository]
[DEBUG]设置系统属性[basedir]=[/Users/aaron/Programs/my_program]
[调试]使用JVM:/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home/bin/Java
[调试]对于/Users/aron/.m2/repository使用优先级为10的manager增强LocalRepositoryManager
[DEBUG]dummy:dummy:jar:1.0(为null选择)
[DEBUG]org.apache.maven.surefire:surefire引导程序:jar:2.7.1:compile(选择用于编译)
[DEBUG]org.apache.maven.surefire:surefireapi:jar:2.7.1:compile(选择用于编译)
[调试]添加到surefire booter测试类路径:/Users/aaron/.m2/repository/org/apache/maven/surefire/surefire booter/2.7.1/surefire-booter-2.7.1.jar范围:编译
[调试]添加到surefire引导程序测试类路径:/Users/aaron/.m2/repository/org/apache/maven/surefire/surefire api/2.7.1/surefire-api-2.7.1.jar范围:编译
[调试]对于/Users/aron/.m2/repository使用优先级为10的manager增强LocalRepositoryManager
[DEBUG]dummy:dummy:jar:1.0(为null选择)
[DEBUG]org.apache.maven.surefire:surefire-junit4:jar:2.7.1:test(选择用于测试)
[DEBUG]org.apache.maven.surefire:surefireapi:jar:2.7.1:test(选择用于测试)
[调试]添加到surefire测试类路径:/Users/aaron/.m2/repository/org/apache/maven/surefire/surefire-junit4/2.7.1/surefire-junit4-2.7.1.jar范围:测试
[调试]添加到surefire测试类路径:/Users/aaron/.m2/repository/org/apache/maven/surefire/surefire api/2.7.1/surefire-api-2.7.1.jar范围:测试
[调试]测试类路径:
[DEBUG]/Users/aaron/Programs/my_program/target/test类
[DEBUG]/Users/alaron/Programs/my_program/target/classes
[DEBUG]/Users/aron/.m2/repository/junit/junit/4.8.1/junit-4.8.1.jar
[调试]对于/Users/aron/.m2/repository使用优先级为10的manager增强LocalRepositoryManager
[DEBUG]dummy:dummy:jar:1.0(为null选择)
[DEBUG]org.apache.maven.surefire:surefire引导程序:jar:2.7.1:compile(选择用于编译)
[DEBUG]org.apache.maven.surefire:surefireapi:jar:2.7.1:compile(选择用于编译)
[调试]添加到surefire booter测试类路径:/Users/aaron/.m2/repository/org/apache/maven/surefire/surefire booter/2.7.1/surefire-booter-2.7.1.jar范围:编译
[调试]添加到surefire引导程序测试类路径:/Users/aaron/.m2/repository/org/apache/maven/surefire/surefire api/2.7.1/surefire-api-2.7.1.jar范围:编译
分叉命令行:/bin/sh-c cd/Users/aaron/Programs/my_program&;&;/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home/bin/Java-jar/Users/aaron/Programs/my_program/target/surefire/6118081963679415631.jar/Users/aaron/program/target/surefire/surefire/4887918564882595612tmp/Users/aaron/Programs/my_计划/目标/surefire/surefire9012255138269731406tmp
-------------------------------------------------------
T T S T S
-------------------------------------------------------
没有要运行的测试。
结果:
测试运行:0,失败:0,错误:0,跳过:0
[信息]------------------------------------------------------------------------
[信息]建立成功
[信息]------------------------------------------------------------------------
[信息]总时间:2.089秒
[信息]完成时间:2011年5月30日星期一12:03:09美国东部夏令时
[信息]最终内存:7M/62M
[信息]------------------------------------------------------------------------
默认情况下,Maven在查找要运行的测试时使用以下命名约定:
Test*
*测试
*测试
()*测试用例
如果您的测试类不遵循这些约定,则应将其重命名或配置Maven Surefire插件,以便为测试类使用另一种模式
<