如何在org.junit下的Eclipse中创建测试套件(How to create a Test Suite in Eclipse under org.junit)

编程入门 行业动态 更新时间:2024-10-28 06:34:27
如何在org.junit下的Eclipse中创建测试套件(How to create a Test Suite in Eclipse under org.junit)

org.junit.Assert. 已弃用junit.framework.Assert

我的问题是如果我的JUnit类没有扩展一个TestCase我该如何在Eclipse中创建一个Test Suite?

当我尝试在Eclipse中创建新的测试套件时,我的类没有出现在选择框中,我想这是因为它们不扩展一个TestCase 。

我认为,新的org.junit我可以使用注释,而不是扩展TestCase

org.junit.Assert. has deprecated junit.framework.Assert

My question is how do I create a Test Suite in Eclipse if my JUnit classes do not extend a TestCase?

When I try to create new Test Suite in Eclipse my classes do not appear in the select box and I imagine this is because they don't extend a TestCase.

I thought that with the new org.junit I can just use annotation and not extend TestCase

最满意答案

以下代码将创建一个包含Junit4的测试套件。 然后,您可以在Eclipse中将其作为Junit测试用例运行。 很显然,TestClasses需要包含用@Test注解的方法,否则没有测试会实际运行该套件。

import org.junit.runners.Suite; @RunWith(Suite.class) @Suite.SuiteClasses({TestClass1.class, TestClass2.class}) public class TestSuite { //nothing }

The following code will create a test suite with Junit4. You can then just run this in Eclipse as a Junit test case. Obviously the TestClasses need to contain methods annotated with @Test otherwise no tests will actually run for the suite.

import org.junit.runners.Suite; @RunWith(Suite.class) @Suite.SuiteClasses({TestClass1.class, TestClass2.class}) public class TestSuite { //nothing }

更多推荐

TestCase,junit,Eclipse,扩展,电脑培训,计算机培训,IT培训"/> <meta name="des

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

发布评论

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

>www.elefans.com

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