JUnit 假设失败理论
JUnit assumptions fail Theories
我正在研究 JUnit @Theory
,发现 assumeTrue(false)
如果忽略它,理论 instrad 将失败。
此代码未通过测试:
@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]
但是当我使用@Test 假设时忽略它。
public class SnippetTest {
@Test
public void validateIndices() {
assumeTrue(false);
}
}
If any of the assumptions fail, the data point is silently ignored.
我错过了什么或做错了什么?
感谢@TamasRev 的评论,我发现了问题所在。看起来,如果所有假设都失败,它将无法通过测试。我发布的情况就是这样,我只有一个假设。
如果我使用 @DataPoints
会发生什么?
这个也失败了
@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);
}
}
但是,如果至少有一个假设通过,那么测试就不会失败。
@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);
}
}
感谢@TamasRev 为我指明了正确的方向。
我正在研究 JUnit @Theory
,发现 assumeTrue(false)
如果忽略它,理论 instrad 将失败。
此代码未通过测试:
@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]
但是当我使用@Test 假设时忽略它。
public class SnippetTest {
@Test
public void validateIndices() {
assumeTrue(false);
}
}
If any of the assumptions fail, the data point is silently ignored.
我错过了什么或做错了什么?
感谢@TamasRev 的评论,我发现了问题所在。看起来,如果所有假设都失败,它将无法通过测试。我发布的情况就是这样,我只有一个假设。
如果我使用 @DataPoints
会发生什么?
这个也失败了
@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);
}
}
但是,如果至少有一个假设通过,那么测试就不会失败。
@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);
}
}
感谢@TamasRev 为我指明了正确的方向。