Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
当我用idea运行所有测试时,它会随机失败,但是当我在tearDown函数中插入以下代码时:
try { Thread.sleep(100); } catch (InterruptedException e) { e.printStackTrace(); }
所有的测试都会通过!不知道为什么,谁能帮我解释一下?
tearDown()在测试类中的每个方法之后运行。因此,您在主线程的测试之间引入了暂停,在此期间,其他线程可能会发生一些并行清理。您应该更改您的方法,以便它们在所有线程中完成所有清理后结束。其他线程也可能涉及测试中涉及的某些类。
tearDown()