RandomizedTesting 介绍
RandomizedTesting 是一个 JUnit 测试的扩展,封装了内置重复随机的测试和超时控制、参数工厂、线程执行组等等。
示例代码:
@ThreadLeakScope(Scope.TEST) @ThreadLeakAction({Action.WARN, Action.INTERRUPT}) @ThreadLeakLingering(linger =1000) publicstaticclasstheGoodBadAndUglyextendsRandomizedTest { @Test publicvoidgood() { // I do nothing and I'm good. } @Test @Repeat(iterations =10) publicvoidbad() { // I fail randomly, about 20% of the time. assertFalse(randomIntBetween(1,100) <=20); } @Test publicvoidugly() { // I start and abandon a thread which falls // outside the test's scope. The test will fail. newThread() { publicvoidrun() { RandomizedTest.sleep(5000); } }.start(); } }
RandomizedTesting 官网
http://labs.carrotsearch.com/randomizedtesting.html
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。