on  it road.com

JUnit 5 Assumptions.assumeFalse()

assumeFalse()将给定的假设验证为假,如果假设为假,则继续进行测试,否则中止测试执行。
它与 assumeTrue()正好相反。

它具有以下重载方法。

public static void assumeFalse(boolean assumption) throws TestAbortedException
public static void assumeFalse(boolean assumption, Supplier<String> messageSupplier) throws TestAbortedException
public static void assumeFalse(boolean assumption, String message) throws TestAbortedException
public static void assumeFalse(BooleanSupplier assumptionSupplier) throws TestAbortedException
public static void assumeFalse(BooleanSupplier assumptionSupplier, String message) throws TestAbortedException
public static void assumeFalse(BooleanSupplier assumptionSupplier, Supplier<String> messageSupplier) throws TestAbortedException
public class AppTest {
	@Test
    void testOnDev() 
	{
		System.setProperty("ENV", "DEV");
        Assumptions.assumeFalse("DEV".equals(System.getProperty("ENV")), AppTest::message);
      //remainder of test will be aborted
    }

	@Test
    void testOnProd() 
	{
		System.setProperty("ENV", "PROD");
        Assumptions.assumeFalse("DEV".equals(System.getProperty("ENV")));
      //remainder of test will proceed

    }

	private static String message () {
		return "TEST Execution Failed :: ";
	}
}
JUnit 5 Assumptions 类

JUnit 5 Assumptions 类提供静态方法来支持基于假设的条件测试执行。
失败的假设会导致测试中止。
当继续执行给定的测试方法没有意义时,通常会使用假设。

在测试报告中,这些测试将被标记为通过。

JUnit jupiter Assumptions类有两个这样的方法:assumeFalse()assumeTrue()

JUnit 5 Assumptions.assumeTrue()

assumeTrue()验证给定的假设为真,如果假设为真测试继续,否则测试执行被中止。

它具有以下重载方法。

public static void assumeTrue(boolean assumption) throws TestAbortedException
public static void assumeTrue(boolean assumption, Supplier<String> messageSupplier) throws TestAbortedException
public static void assumeTrue(boolean assumption, String message) throws TestAbortedException
public static void assumeTrue(BooleanSupplier assumptionSupplier) throws TestAbortedException
public static void assumeTrue(BooleanSupplier assumptionSupplier, String message) throws TestAbortedException
public static void assumeTrue(BooleanSupplier assumptionSupplier, Supplier<String> messageSupplier) throws TestAbortedException
public class AppTest {
	@Test
    void testOnDev() 
	{
		System.setProperty("ENV", "DEV");
        Assumptions.assumeTrue("DEV".equals(System.getProperty("ENV")));
        //remainder of test will proceed
    }

	@Test
    void testOnProd() 
	{
		System.setProperty("ENV", "PROD");
        Assumptions.assumeTrue("DEV".equals(System.getProperty("ENV")), AppTest::message);
        //remainder of test will be aborted
    }

	private static String message () {
		return "TEST Execution Failed :: ";
	}
}
日期:2020-09-17 00:09:53 来源:oir作者:oir