Junit:如何处理junit测试用例中的类级别变量

发布于 2025-01-14 02:53:06 字数 451 浏览 1 评论 0原文

在下面的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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文