有没有办法可以在拆解( @After )方法中获得测试结果?我希望在测试后根据结果进行清理。
Is there any way I can get the test result in the teardown (@After) method? I'd like to do clean up after the tests depending on the result.
找不到关于 @After 在junit docs中。
Could not find much details about @After in the junit docs.
推荐答案最接近你要求的东西可能是 TestWatcher 规则。这不会让您访问返回的结果或任何内容,但您可以使用它(或创建自己的 TestRule 并结合Description对象,您可以对方法进行不同的注释,以指示需要进行哪种清理。
The closest thing to what you're asking for would probably be the TestWatcher rule. That won't give you access to a returned result or anything, but you can use it (or create your own TestRule and combined with the Description object, you could annotate your methods differently to indicate what sort of clean-up is necessary.
更多推荐
JUnit 4.11在@After中获得测试结果
发布评论