[英]how do I test constructor in java which refers to current object?
My code doesn't meet the sonarqube code coverage the following piece of constructor says it needs test in sonarqube, I have written the following code to test it but it is not covering the code?我的代码不符合 sonarqube 代码覆盖率以下构造函数说它需要在 sonarqube 中测试,我编写了以下代码来测试它,但它没有覆盖代码? can some one help me where I am going wrong?有人可以帮助我哪里出错了吗?
@Test
public void OrderBuilderIT() {
errorQueue.equals("amq:ORDER.T.SYSTEM.ERROR");
}
public OrderBuilder(String errorQueue) {
this.errorQueue = errorQueue;
}
the code does not seem to be covered代码似乎没有被覆盖
I am assuming that you are trying to test the constructor call for the class with the error queue field value that you are passing while constructing and expecting the same value to be asserted.我假设您正在尝试使用错误队列字段值测试类的构造函数调用,该值是在构造和期望声明相同值时传递的。 Actually, your check does nothing in terms of an assertion.实际上,您的支票在断言方面没有任何作用。
Below is an assumption that you may be trying to achieve.以下是您可能试图实现的假设。 Also, should cover your sonar issue.此外,应该涵盖您的声纳问题。
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;
import org.junit.jupiter.api.Test;
public class SomeConstructorTest {
private OrderBuilder orderBuilder;
@Test
public void orderBuilderTestWithIncorrectErrorQueueMessage(){
String expected = "amq:ORDER.T.SYSTEM.ERROR";
String errorQueue = "dummyString";
orderBuilder = new OrderBuilder(errorQueue);
assertThat(expected, is(errorQueue)); // should fail if you are asserting string content
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.