发布运行测试

时间:2019-03-20 18:17:53

标签: junit5 jmockit java-11

因此,我用Jmockit编写了测试用例,并在我的开发机上用Java 8和junit 4运行它们。我们的Bamboo服务器安装了Java 10,并且我在所有测试中始终收到错误:

import jslib = require("jslib");

我认为这可能是与junit4 / java11 / jmockit的兼容性问题。我已经将代码重构为使用junit 5,但是现在没有注入任何模拟,并且由于IE:未创建db对象或空指针而收到很多其他问题:

declare module "jslib";

似乎没有模拟对象被注入。测试用例如下:

build   20-Mar-2019 11:58:10    [INFO] Tests run: 8, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 2.915 s - in org.tsocs.txn.OCSServiceTest
build   20-Mar-2019 11:58:10    [INFO] Running org.tsocs.ws.services.RolloverBundleTest
build   20-Mar-2019 11:58:11    [ERROR] Tests run: 8, Failures: 0, Errors: 8, Skipped: 0, Time elapsed: 0.684 s <<< FAILURE! - in org.tsocs.ws.services.RolloverBundleTest
build   20-Mar-2019 11:58:11    [ERROR] failInvalidBundle(org.tsocs.ws.services.RolloverBundleTest)  Time elapsed: 0.303 s  <<< ERROR!
build   20-Mar-2019 11:58:11    java.lang.IllegalStateException: 
build   20-Mar-2019 11:58:11    Missing @Tested or @Injectable for parameter "year" in constructor Timestamp(int year, int month, int date, int hour, int minute, int second, int nano)
build   20-Mar-2019 11:58:11      when initializing field "Timestamp tradeStartTime"
build   20-Mar-2019 11:58:11      of @Tested object "RolloverBundle testService"
build   20-Mar-2019 11:58:11    
build   20-Mar-2019 11:58:11    [ERROR] successUpdateBundleWithNoRolloverAmountAndSendSMS(org.tsocs.ws.services.RolloverBundleTest)  Time elapsed: 0.039 s  <<< ERROR!
build   20-Mar-2019 11:58:11    java.lang.IllegalStateException: 
build   20-Mar-2019 11:58:11    Missing @Tested or @Injectable for parameter "year" in constructor Timestamp(int year, int month, int date, int hour, int minute, int second, int nano)
build   20-Mar-2019 11:58:11      when initializing field "Timestamp tradeStartTime"
build   20-Mar-2019 11:58:11      of @Tested object "RolloverBundle testService"
build   20-Mar-2019 11:58:11    
build   20-Mar-2019 11:58:11    [ERROR] failNotRollOverBundle(org.tsocs.ws.services.RolloverBundleTest)  Time elapsed: 0.039 s  <<< ERROR!
build   20-Mar-2019 11:58:11    java.lang.IllegalStateException: 
build   20-Mar-2019 11:58:11    Missing @Tested or @Injectable for parameter "year" in constructor Timestamp(int year, int month, int date, int hour, int minute, int second, int nano)
build   20-Mar-2019 11:58:11      when initializing field "Timestamp tradeStartTime"
build   20-Mar-2019 11:58:11      of @Tested object "RolloverBundle testService"
build   20-Mar-2019 11:58:11    
build   20-Mar-2019 11:58:11    [ERROR] successRolloverTransfer(org.tsocs.ws.services.RolloverBundleTest)  Time elapsed: 0.041 s  <<< ERROR!
build   20-Mar-2019 11:58:11    java.lang.IllegalStateException: 
build   20-Mar-2019 11:58:11    Missing @Tested or @Injectable for parameter "year" in constructor Timestamp(int year, int month, int date, int hour, int minute, int second, int nano)
build   20-Mar-2019 11:58:11      when initializing field "Timestamp tradeStartTime"
build   20-Mar-2019 11:58:11      of @Tested object "RolloverBundle testService"
build   20-Mar-2019 11:58:11    
build   20-Mar-2019 11:58:11    [ERROR] failBundleAlreadyTransferred(org.tsocs.ws.services.RolloverBundleTest)  Time elapsed: 0.039 s  <<< ERROR!
build   20-Mar-2019 11:58:11    java.lang.IllegalStateException: 
build   20-Mar-2019 11:58:11    Missing @Tested or @Injectable for parameter "year" in constructor Timestamp(int year, int month, int date, int hour, int minute, int second, int nano)
build   20-Mar-2019 11:58:11      when initializing field "Timestamp tradeStartTime"
build   20-Mar-2019 11:58:11      of @Tested object "RolloverBundle testService"
build   20-Mar-2019 11:58:11    
build   20-Mar-2019 11:58:11    [ERROR] failInsufficientFundsForTransfer(org.tsocs.ws.services.RolloverBundleTest)  Time elapsed: 0.041 s  <<< ERROR!
build   20-Mar-2019 11:58:11    java.lang.IllegalStateException: 
build   20-Mar-2019 11:58:11    Missing @Tested or @Injectable for parameter "year" in constructor Timestamp(int year, int month, int date, int hour, int minute, int second, int nano)
build   20-Mar-2019 11:58:11      when initializing field "Timestamp tradeStartTime"
build   20-Mar-2019 11:58:11      of @Tested object "RolloverBundle testService"
build   20-Mar-2019 11:58:11    
build   20-Mar-2019 11:58:11    [ERROR] failInsufficientFundsToRollover(org.tsocs.ws.services.RolloverBundleTest)  Time elapsed: 0.041 s  <<< ERROR!
build   20-Mar-2019 11:58:11    java.lang.IllegalStateException: 
build   20-Mar-2019 11:58:11    Missing @Tested or @Injectable for parameter "year" in constructor Timestamp(int year, int month, int date, int hour, int minute, int second, int nano)
build   20-Mar-2019 11:58:11      when initializing field "Timestamp tradeStartTime"
build   20-Mar-2019 11:58:11      of @Tested object "RolloverBundle testService"
build   20-Mar-2019 11:58:11    
build   20-Mar-2019 11:58:11    [ERROR] failBundleExpiredOrDepleted(org.tsocs.ws.services.RolloverBundleTest)  Time elapsed: 0.043 s  <<< ERROR!
build   20-Mar-2019 11:58:11    java.lang.IllegalStateException: 
build   20-Mar-2019 11:58:11    Missing @Tested or @Injectable for parameter "year" in constructor Timestamp(int year, int month, int date, int hour, int minute, int second, int nano)
build   20-Mar-2019 11:58:11      when initializing field "Timestamp tradeStartTime"
build   20-Mar-2019 11:58:11      of @Tested object "RolloverBundle testService"

我已经查看了jmockit github页面中的示例,但是看不到我在做任何异常的事情。我在surefire插件中定义了代理arg行:

[ERROR] Tests run: 8, Failures: 0, Errors: 8, Skipped: 0, Time elapsed: 0.183 s <<< FAILURE! - in org.tsocs.ws.services.RolloverBundleTest
[ERROR] failInvalidBundle  Time elapsed: 0.031 s  <<< ERROR!
java.lang.NullPointerException
    at org.tsocs.ws.services.RolloverBundleTest.failInvalidBundle(RolloverBundleTest.java:396)

[ERROR] successUpdateBundleWithNoRolloverAmountAndSendSMS  Time elapsed: 0.03 s  <<< ERROR!
java.lang.NullPointerException
    at org.tsocs.ws.services.RolloverBundleTest.successUpdateBundleWithNoRolloverAmountAndSendSMS(RolloverBundleTest.java:125)

[ERROR] failNotRollOverBundle  Time elapsed: 0.014 s  <<< ERROR!
java.lang.NullPointerException
    at org.tsocs.ws.services.RolloverBundleTest.failNotRollOverBundle(RolloverBundleTest.java:599)

[ERROR] successRolloverTransfer  Time elapsed: 0.036 s  <<< ERROR!
java.lang.NullPointerException
    at org.tsocs.ws.services.RolloverBundleTest.successRolloverTransfer(RolloverBundleTest.java:225)

[ERROR] failBundleAlreadyTransferred  Time elapsed: 0.015 s  <<< ERROR!
java.lang.NullPointerException
    at org.tsocs.ws.services.RolloverBundleTest.failBundleAlreadyTransferred(RolloverBundleTest.java:461)

[ERROR] failInsufficientFundsForTransfer  Time elapsed: 0.016 s  <<< ERROR!
java.lang.NullPointerException
    at org.tsocs.ws.services.RolloverBundleTest.failInsufficientFundsForTransfer(RolloverBundleTest.java:320)

[ERROR] failInsufficientFundsToRollover  Time elapsed: 0.015 s  <<< ERROR!
java.lang.NullPointerException
    at org.tsocs.ws.services.RolloverBundleTest.failInsufficientFundsToRollover(RolloverBundleTest.java:678)

[ERROR] failBundleExpiredOrDepleted  Time elapsed: 0.015 s  <<< ERROR!
java.lang.NullPointerException
    at org.tsocs.ws.services.RolloverBundleTest.failBundleExpiredOrDepleted(RolloverBundleTest.java:524)

这是我第一次使用jmockit(带有嘲笑声的tho am familair),非常感谢任何帮助

环境:

  • 操作系统:macOS Mojave 10.14.3
  • JDK:11.0.2-amzn
  • maven:3.6.0
  • junit:5.4.1
  • jmockit:1.45

1 个答案:

答案 0 :(得分:0)

由于Jmockit框架抱怨java.sql.Timestamp构造函数的缺少字段,所以我添加了:

@Injectable
private int year, month, date, hour, minute, seconds, nano;

测试正在JDK 10和11下进行