gpt4 book ai didi

java - junit 理论解析为 ParameterizedAssertionError 而不是失败

转载 作者:行者123 更新时间:2023-12-01 13:23:31 27 4
gpt4 key购买 nike

我像这样进行理论测试

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

最佳答案

我已经尝试过这个:

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)

如您所见,您的消息就在那里。你有什么不同吗?

关于java - junit 理论解析为 ParameterizedAssertionError 而不是失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21908990/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com