0

我像这样运行理论测试

@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.
4

2 回答 2

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

在Failure Trace窗口设置为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)

如您所见,您的信息就在那里。你有什么不一样的吗?

于 2014-02-20T13:30:35.573 回答
0

升级到 JUnit 4.12。他们在那个版本中修复了它,看:https ://github.com/junit-team/junit/pull/607

于 2016-01-14T10:18:47.367 回答