Merge pull request #9648 from dpgarrett/danielg/conditionally-ignoring-tests-in-junit

BAEL-4337 Conditionalling ignoring tests in JUnit 4
This commit is contained in:
bfontana 2020-07-16 21:09:58 -03:00 committed by GitHub
commit 2d8bc57689
1 changed files with 41 additions and 0 deletions

View File

@ -0,0 +1,41 @@
package com.baeldung.assume;
import static org.hamcrest.Matchers.is;
import static org.junit.Assert.assertEquals;
import static org.junit.Assume.assumeFalse;
import static org.junit.Assume.assumeThat;
import static org.junit.Assume.assumeTrue;
import org.junit.Test;
public class ConditionallyIgnoreTestsUnitTest {
@Test
public void whenAssumeThatCodeVersionIsNot2_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());
}
@Test
public void whenAssumeFalseOnCondition_thenIgnore() {
final int codeVersion = 2;
assumeFalse(isCodeVersion2(codeVersion));
assertEquals("hello", "HELLO".toLowerCase());
}
private boolean isCodeVersion2(final int codeVersion) {
return codeVersion == 2;
}
}