并行集成测试处理数据库计数

发布于 2025-01-30 12:39:49 字数 129 浏览 3 评论 0原文

我正在并行运行集成测试,但是我有一个测试,可以计算一个表中的行数,但数量可能会因在测试运行之前进行的许多测试而有所不同。

在春季或JUNIT中是否有任何机制可以使我确保测试运行时,该表是干净的,以使计数总是1?

谢谢

I'm running my integration tests in parallel but I have one tests that counts the number of rows in one table but the number can vary depending on many tests have run before that tests runs.

Is there any mechanism in Spring or Junit that would allow me to make sure that when that tests runs that table is clean so that the count would always be 1?

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

厌味 2025-02-06 12:39:49

您可以在Junit类中使用注释前:

@BeforeEach
void foo() {
    clearDBrows();
}

void clearDBrows(){
//clear db rows 
..
}

这是通过考虑,您的其他测试真的不在乎db表行是否在执行之前被清除,因为@beforeeach将对每个执行您运行的测试。

You can use BeforeEach annotation within Junit class:

@BeforeEach
void foo() {
    clearDBrows();
}

void clearDBrows(){
//clear db rows 
..
}

This is by considering, your other test's wont really care if db table rows get cleared before execution as @BeforeEach will get executed for every tests you run.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文