junit5 入门系列教程-06-junit5 假设(Assumptions)

时间:2025-03-27 09:23:58
package .junit5; import static ; import static ; import static ; import ; /** * @author houbinbin * @version 1.0 * @since JDK 1.7 */ public class AssumptionsDemo { @Test void testOnlyOnCiServer() { assumeTrue("CI".equals(("ENV"))); // remainder of test } @Test void testOnlyOnDeveloperWorkstation() { assumeTrue("DEV".equals(("ENV")), () -> "Aborting test: not on developer workstation"); // remainder of test } @Test void testInAllEnvironments() { assumingThat("CI".equals(("ENV")), () -> { // perform these assertions only on the CI server assertEquals(2, 2); }); // perform these assertions in all environments assertEquals("a string", "a string"); } }