gpt4 book ai didi

maven - 使用 Junit 和 Maven 运行测试的交集

转载 作者:行者123 更新时间:2023-12-04 12:53:40 25 4
gpt4 key购买 nike

我使用 Spring @IfProfileValue 标志识别了许多测试

@IfProfileValue{"a", "c"}
@Test
public void testA{ Do Stuff }

@IfProfileValue{"a", "b"}
@Test
public void testB{ Do Stuff }

@IfProfileValue{"a", "b"}
@Test
public void testC{ Do Stuff }

@IfProfileValue{"b"}
@Test
public void testD{ Do Stuff }

我可以使用运行所有测试
mvm clean install -Dtest-group=a -Dtest-group=b

我只想运行与 @IfProfileValue={"a","b") 匹配的测试(测试 B/C)
那么有没有办法使用 maven 只运行这两个值的交集?

最佳答案

编辑:
您可以使用 @ProfileValueSourceConfiguration@ and provide your own implementation of 注释该类ProfileValueSource`,如 this answer 中所述.

看起来单独使用 Maven 是不可能的。看起来它可以从多个具有相同名称的参数构建数组:

mvn test -Dtest-group=a -Dtest-group=c

将运行带有 @IfProfileValue(name = "test-group", values = {"c"}) 注释的测试.逗号符号都不起作用,它会将 'a,c' 视为文字:
    mvn test -Dtest-group=a,c

<project 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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>net.s17t</groupId>
<artifactId>showcase</artifactId>
<version>0.0.1-SNAPSHOT</version>

<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-framework-bom</artifactId>
<version>4.1.6.RELEASE</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>

<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
</dependency>

<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compier-plugin</artifactId>
<version>3.3</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>

java 代码:

package showcase;

import static org.junit.Assert.*;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.context.annotation.Configuration;
import org.springframework.test.annotation.IfProfileValue;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.TestExecutionListeners;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.support.AnnotationConfigContextLoader;

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(loader=AnnotationConfigContextLoader.class)
@TestExecutionListeners
public class SimpleTest {

@Configuration
static class ContextConfiguration {

}

@Test
@IfProfileValue(name = "test-group", values = {"a", "b"})
public void testPhoneLogIsReadable() {
System.out.println("I'm a and b");
assertTrue("Phone log is not readable.", true);
}

@Test
@IfProfileValue(name = "test-group", values = {"c"})
public void testPhoneLogHasRecords() {
System.out.println("I'm c");
assertFalse("Phone log does not have records.", false);
}

}

关于maven - 使用 Junit 和 Maven 运行测试的交集,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29281843/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com