JUnit assumptions fail Theories

蓝咒 提交于 2019-12-12 17:51:37

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!