我像这样进行理论测试
@Theory
public void qlIsNotNullAndReservationWithRefIdDoesntHaveItemReference(
@TestedOn(ints = {100, 200, 300}) final int value) {
assertTrue("should be no error", false);
}
它总是会在ParameterizedAssertionError错误中结束而没有任何有意义的消息。
因为无论如何要显示消息的“正确”失败?
日志:
[INFO] --- maven-compiler-plugin:2.5.1:testCompile (default-testCompile) @ stock ---
[INFO] Compiling 25 source files to /Users/user/repository/reboot/trunk/company-stock/target/test-classes
[INFO]
[INFO] --- maven-surefire-plugin:2.14.1:test (default-test) @ stock ---
[INFO] Surefire report directory: /Users/user/repository/reboot/trunk/company-stock/target/surefire-reports
-------------------------------------------------------
T E S T S
-------------------------------------------------------
Picked up _JAVA_OPTIONS: -Xms1024m -Xmx1024m -XX:MaxPermSize=512m
Running de.company.stock.webservice.CornerCaseAnalysisIT
Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 0.265 sec <<< FAILURE!
test1(de.company.stock.webservice.CornerCaseAnalysisIT) Time elapsed: 0.082 sec <<< ERROR!
org.junit.experimental.theories.internal.ParameterizedAssertionError: test1(ints)
at org.junit.Assert.fail(Assert.java:88)
at org.junit.Assert.failNotEquals(Assert.java:743)
at org.junit.Assert.assertEquals(Assert.java:118)
at org.junit.Assert.assertEquals(Assert.java:555)
at de.company.stock.webservice.CornerCaseAnalysisIT.test1(CornerCaseAnalysisIT.java:60)
Results :
Tests in error:
? ParameterizedAssertion test1(ints)
Tests run: 1, Failures: 0, Errors: 1, Skipped: 0
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 46.763s
[INFO] Finished at: Thu Feb 20 17:57:56 CET 2014
[INFO] Final Memory: 34M/989M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.14.1:test (default-test) on project stock: There are test failures.
答案 0 :(得分:1)
我试过这个:
package com.junit.theory;
import static org.junit.Assert.*;
import org.junit.Test;
import org.junit.experimental.theories.Theories;
import org.junit.experimental.theories.Theory;
import org.junit.experimental.theories.suppliers.TestedOn;
import org.junit.runner.RunWith;
@RunWith(Theories.class)
public class TheoryTry {
@Theory
public void tryTheory(
@TestedOn(ints = {100, 200, 300}) final int point) {
assertTrue("should be no error", false);
}
}
得到的痕迹是:
org.junit.experimental.theories.internal.ParameterizedAssertionError: tryTheory(ints)
at org.junit.experimental.theories.Theories$TheoryAnchor.reportParameterizedError(Theories.java:192)
...
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
Caused by: java.lang.AssertionError: should be no error <---LOOK HERE!
at org.junit.Assert.fail(Assert.java:88)
...
at org.junit.experimental.theories.Theories$TheoryAnchor$1$1.evaluate(Theories.java:141)
... 20 more
在“故障跟踪”窗口中设置为Filtered
,只有三行:
org.junit.experimental.theories.internal.ParameterizedAssertionError: tryTheory(ints)
Caused by: java.lang.AssertionError: should be no error <---LOOK HERE!
at com.junit.theory.TheoryTry.tryTheory(TheoryTry.java:18)
正如您所看到的,您的信息就在那里。你有不同的东西吗?
答案 1 :(得分:0)
升级到JUnit 4.12。 他们在那个版本中修复了它, 看:https://github.com/junit-team/junit/pull/607