From e955c836adb16087392f1f29aa0b6c2d8a7ad5d6 Mon Sep 17 00:00:00 2001 From: Daniel Garrett Date: Mon, 6 Jul 2020 11:07:36 +0100 Subject: [PATCH] feat: add class to conditionally ignore unit tests --- .../ConditionallyIgnoreTestsUnitTest.java | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 testing-modules/junit-4/src/test/java/com/baeldung/assume/ConditionallyIgnoreTestsUnitTest.java diff --git a/testing-modules/junit-4/src/test/java/com/baeldung/assume/ConditionallyIgnoreTestsUnitTest.java b/testing-modules/junit-4/src/test/java/com/baeldung/assume/ConditionallyIgnoreTestsUnitTest.java new file mode 100644 index 0000000000..af571eb808 --- /dev/null +++ b/testing-modules/junit-4/src/test/java/com/baeldung/assume/ConditionallyIgnoreTestsUnitTest.java @@ -0,0 +1,32 @@ +package com.baeldung.assume; + +import static org.hamcrest.Matchers.is; +import static org.junit.Assert.assertEquals; +import static org.junit.Assume.assumeThat; +import static org.junit.Assume.assumeTrue; + +import org.junit.Test; + +public class ConditionallyIgnoreTestsUnitTest { + + + @Test + public void whenAssumeThatCodeVersionIsNot1_thenIgnore() { + final int codeVersion = 1; + assumeThat(codeVersion, is(2)); + + assertEquals("hello", "HELLO".toLowerCase()); + } + + @Test + public void whenAssumeTrueOnCondition_thenIgnore() { + final int codeVersion = 1; + assumeTrue(isCodeVersion2(codeVersion)); + + assertEquals("hello", "HELLO".toLowerCase()); + } + + private boolean isCodeVersion2(final int codeVersion) { + return codeVersion == 2; + } +}