Java Junit4和TestNG在一个带有Maven和继承的项目中
我和你有同样的问题,但我仍然有问题。 我创建了一个需要使用junit4和testng的简单项目 下面是根pom:Java Junit4和TestNG在一个带有Maven和继承的项目中,java,maven,junit,testng,Java,Maven,Junit,Testng,我和你有同样的问题,但我仍然有问题。 我创建了一个需要使用junit4和testng的简单项目 下面是根pom: com.dimas.testmodule 家长 0.0.001 家长 聚甲醛 3.0.5.1发布 测试 2.9 朱尼特 朱尼特 4.7 测试 等 ${project.artifactId} org.apache.maven.plugins maven编译器插件 2.3.2 1.6 1.6 违约 真的 少年 仅测试 测试模块 org.apache.maven.plugins maven
com.dimas.testmodule
家长
0.0.001
家长
聚甲醛
3.0.5.1发布
测试
2.9
朱尼特
朱尼特
4.7
测试
等
${project.artifactId}
org.apache.maven.plugins
maven编译器插件
2.3.2
1.6
1.6
违约
真的
少年
仅测试
测试模块
org.apache.maven.plugins
maven surefire插件
${maven.surefire.plugin.version}
假的
**/*NGTest.java
仅测试
少年
仅测试
测试模块
org.apache.maven.plugins
maven surefire插件
${maven.surefire.plugin.version}
假的
**/*NGTest.java
模块JUnitOnly和TestModule只是继承,不覆盖任何属性。以下是测试结果
com.dimas.testmodule.testngonly
仅测试
0.0.001
仅测试
com.dimas.testmodule
家长
0.0.001
org.testng
testng
6.3.1
假如
测试
org.apache.maven.plugins
maven surefire插件
${maven.surefire.plugin.version}
假的
src\test\resources\my-testng.xml
我需要忽略默认配置文件的testng测试,只为配置文件testNGOnly启动testng测试。有三个模块-
junit
、testng
和mixed
默认配置文件应该只执行junit测试,即运行junit
module和运行mixed
module的junit测试testNG
配置文件应仅执行testNG测试,即运行testNG
模块并运行混合
模块的testNG测试
按照maven中配置文件的工作方式,不可能排除配置文件中的模块。但是,不需要构建不需要的模块
因此,在默认配置文件中,具有模块junit
和混合
在testNG配置文件中,添加模块testNG
按照maven最佳实践,在
内的父pom中定义
。这允许我们只在junit
模块中使用junit依赖项,在testNG
模块中使用testNG依赖项
三个模块之间的surefire
配置没有共同之处,因此不需要在父pom中指定
由于不需要在testNG
profile中运行junit测试,因此在testNG
profile中为junit
模块添加一个插件配置
使用SO问题的提示配置mixed
pom。由于surefire需要基于概要文件使用junit或testng runner,因此这变得很棘手
我已将上述建议合并到一个示例项目中。共有三个模块-junit
、testng
和mixed
默认配置文件应该只执行junit测试,即运行junit
module和运行mixed
module的junit测试testNG
配置文件应仅执行testNG测试,即运行testNG
模块并运行混合
模块的testNG测试
按照maven中配置文件的工作方式,不可能排除配置文件中的模块。但是,不需要构建不需要的模块
因此,在默认配置文件中,具有模块junit
和混合
在testNG配置文件中,添加模块testNG
遵循maven最佳实践,定义<