忽略基于环境的测试用例 [英] Ignore Test Cases Based on Environment

查看:98
本文介绍了忽略基于环境的测试用例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何让Maven忽略基于变量或构建配置文件的特定测试用例?

How would I have maven ignore specific test cases based on a variable or an build profile?

我有一些测试案例,涉及连接到LDAP服务器.如果使用特定配置文件或将Maven变量传递到命令中进行构建,我将如何忽略这些测试用例?我不想忽略所有测试用例.

I have a few test cases that involve connecting to an LDAP server. How would I get these test cases to be ignored if I am building with a specific profile or a maven variable being passed into the command? I do not wish to ignore all test cases.

推荐答案

您的解决方案似乎包括两个部分:(1)通过Maven通知该进程正在给定的配置中运行,以及(2)运行一个根据该配置进行有条件的测试.

Your solution seems to be two parts: (1) informing the process, through Maven, that it is running in a given configuration, and (2) running a test conditionally based on that configuration.

第一点很容易:使用-D开关传递系统属性,如这样的答案,确认您需要使用

The first bit is easy: Use the -D switch to pass in a system property, as in this SO answer, acknowledging that you need to pass a system property as an argument within a system property using the surefire argLine property:

mvn -DargLine="-DldapTests=disable" test

第二步,您可以在JUnit中使用新的assumeTrue和相关的假设API,如

For the second, you can use the new assumeTrue and related assumption API in JUnit, as in this other SO answer.

@Before
public void checkLdapTests() {
  assumeThat(System.getProperty("ldapTests"), is(not(equalTo("disable"))));
}

这篇关于忽略基于环境的测试用例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆