问题
I was messing arround with JUnit @Theory and find out that assumeTrue(false) fails the theory instrad if ignore it.
This code fail the test:
@RunWith(Theories.class)
public class SnippetTest {
   @Theory
   public void validateIndices(){
       assumeTrue(false);
   }
}
SnippetTest.validateIndices Never found parameters that satisfied method assumptions. Violated assumptions: [org.junit.AssumptionViolatedException: got: false, expected: is true]
But when I'm using @Test assumption ignore it.
public class SnippetTest {
    @Test
    public void validateIndices() {
        assumeTrue(false);
    }
}
It's contraversial with Theories Documentation.
If any of the assumptions fail, the data point is silently ignored.
What am I missing or what am doing wrong?
回答1:
Thanks to @TamasRev comment I found what was going wrong. Looks like, it will fail the test in case all the the assumption fails. Im the case I posted, I have only one assumption.
What is happening if I'm using @DataPoints?
This one fails as well
@RunWith(Theories.class)
public class SnippetTest {
    @DataPoints
    public static boolean[] data(){
        return new boolean[]{false, false};
    }
   @Theory
   public void validateIndices(boolean data){
       assumeTrue(data);
       assertTrue(true);
   }
}
But when if at least one assumption pass then test is not failed.
@RunWith(Theories.class)
public class SnippetTest {
    @DataPoints
    public static boolean[] data(){
        return new boolean[]{false, true};
    }
   @Theory
   public void validateIndices(boolean data){
       assumeTrue(data);
       assertTrue(true);
   }
}
Thanx @TamasRev for pointing me to right direction.
来源:https://stackoverflow.com/questions/37572980/junit-assumptions-fail-theories