Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/maven/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Junit4和TestNG在一个带有Maven和继承的项目中_Java_Maven_Junit_Testng - Fatal编程技术网

Java Junit4和TestNG在一个带有Maven和继承的项目中

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

我和你有同样的问题,但我仍然有问题。 我创建了一个需要使用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 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最佳实践,定义
<