具有Junit 5的Maven故障安全插件-无法使用命令行和Junit 5 @Tag运行筛选的组

时间:2018-11-28 11:51:13

标签: maven junit5 maven-failsafe-plugin

我正在尝试使用Junit 5标签运行故障安全插件进行集成测试。我用于故障保护的POM.xml看起来像:

<plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-failsafe-plugin</artifactId>
            <version>${maven.failsafe.version}</version>
            <configuration>
                <systemProperties>
                    <phantomjs.binary.path>${phantomjs.binary.path}</phantomjs.binary.path>
                    <webdriver.chrome.driver>${webdriver.chrome.driver}</webdriver.chrome.driver>
                    <webdriver.ie.driver>${webdriver.ie.driver}</webdriver.ie.driver>
                    <webdriver.edge.driver>${webdriver.edge.driver}</webdriver.edge.driver>
                    <webdriver.gecko.driver>${webdriver.gecko.driver}</webdriver.gecko.driver>
                    <webdriver.opera.driver>${webdriver.opera.driver}</webdriver.opera.driver>
                    <selenium.wait.timeout>30</selenium.wait.timeout>
                </systemProperties>
                <configuration>
                    <groups>EveryDay|Today</groups>
                    <excludedGroups>integration, regression</excludedGroups>
                </configuration>
            </configuration>
            <executions>
                <execution>
                    <goals>
                        <goal>integration-test</goal>
                        <goal>verify</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>

并尝试这样做:

mvn -Dgroups=Today verify

它无法正常运行并运行整个套件。有什么想法吗?

我的测试方法如下:

@Test
@Tag("EveryDay")
@Tag("Today")
@DisplayName("Activities")
public void activitiesTest(){ // Some test code here }

和我的测试班:

@ExtendWith({SpringExtension.class})
@ContextConfiguration(classes = { WebDriverConfig.class, LoggerConfig.class, EmailConfig.class})
@TestExecutionListeners(listeners= {ScreenshotTaker.class, DependencyInjectionTestExecutionListener.class, RunnerExtension.class})
public class BasicScenariosIT {
// Code 
}

1 个答案:

答案 0 :(得分:0)

实际上,解决方案非常简单... 在我的maven pom.xml中,在故障安全插件中:

<plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-failsafe-plugin</artifactId>
                <version>${maven.failsafe.version}</version>
                <configuration>

                    <groups>${test.included.groups}</groups>
                    <excludedGroups>${test.excluded.groups}</excludedGroups>

                </configuration>
                <executions>
                    <execution>
                        <goals>
                            <goal>integration-test</goal>
                            <goal>verify</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>

注意参数:

${test.included.groups}
${test.excluded.groups}

在我的junit 5测试中:

@Test
@Tag("EveryDay")
@Tag("Today")
@DisplayName("Activities")
public void activitiesTest(){ // Some test code here }

和命令:

mvn -Dtest.included.groups=Today verify

就是这样!