– Start
如果有些测试用例只有在特定条件运行,我们可以使用 Assumptions
package demo08;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Assumptions;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
class AssumptionTest {
@BeforeAll
static void setUpBeforeClass() throws Exception {
System.getProperty("env", "uat");
}
@Test
void test() {
// 假定是 dev 环境,如果不是则返回,测试用例显示成功
String env = System.getProperty("env");
Assumptions.assumeTrue("dev".equals(env));
Assertions.assertTrue(1 == 2);
}
}
– 更多参见:JUnit 精萃
– 声 明:转载请注明出处
– Last Updated on 2019-08-12
– Written by ShangBo on 2019-08-12
– End