其他分享
首页 > 其他分享> > JUnit 假定先决条件

JUnit 假定先决条件

作者:互联网

– 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

标签:假定,junit,先决条件,api,jupiter,env,org,import,JUnit
来源: https://blog.csdn.net/shangboerds/article/details/99288385