Junit:如何处理junit测试用例中的类级别变量
在下面的incrementId()方法中,我需要测试id >比条件大 MAX_NUM 个。
pubic class ClassATest {
AtomicInteger atomicInt = new AtomicInteger (0)
public static final int MAX_NUM = 1000
pulic long incrementId() {
long id = atomicInt.incrementAndGet();
if (id > MAX_NUM ) {
System.out.println("need to be tested....")
}
}
}
是否可以模拟上面的atomicInt对象?或者有什么方法可以在不影响性能的情况下测试上述if条件?
有人可以帮我解决这个问题吗?
In the below incrementId() method, I need to test id > MAX_NUM greater than the condition.
pubic class ClassATest {
AtomicInteger atomicInt = new AtomicInteger (0)
public static final int MAX_NUM = 1000
pulic long incrementId() {
long id = atomicInt.incrementAndGet();
if (id > MAX_NUM ) {
System.out.println("need to be tested....")
}
}
}
Is it possible to mock the above atomicInt object? or is there any way to test above if condition without affecting the performance?
Can someone please help me on this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论