JUnit 4.11在@After中获得测试结果

编程入门 行业动态 更新时间:2024-10-10 00:22:19
本文介绍了JUnit 4.11在@After中获得测试结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

有没有办法可以在拆解( @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中获得测试结果

本文发布于:2023-10-31 06:47:26,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1545331.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:测试   JUnit

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!