简体   繁体   English

从Eclipse内部运行JUnit测试套件

[英]Running JUnit test suite from inside Eclipse

Historically, I've always written my unit tests like this: 从历史上看,我总是像这样编写单元测试:

public void WidgetTest {
    @Test
    public void test_whatever() {
        // Given...

        // When...

        // Then...
    }
}

This allows me to right-click my test file in Eclipse and Run As >> JUnit , and test that 1 particular test, directly from inside Eclipse. 这使我可以在Eclipse和Run As >> JUnit右键单击测试文件,然后直接从Eclipse内部测试该特定测试。 Then, when doing a local (Ant-based) build, I configure a <junit> Ant task to run all of my src/test/java tests at once. 然后,在进行本地(基于Ant的)构建时,我配置了<junit> Ant任务以一次运行所有src/test/java测试。

I'm now looking for an in-between solution. 我现在正在寻找一种中间解决方案。 That is, a way to run all of my test classes from inside Eclipse, all at once, with the click of a button. 也就是说,只需单击一个按钮,即可一次从Eclipse内部运行所有测试类的方法。 A co-worker recommended that Junit has a notion of a "test suite" that I could attach all of my test classes to, but it looks like this test suite is some sort of JAR/tool that I don't want to include in my project. 一位同事建议Junit有一个“测试套件”的概念,我可以将我的所有测试类都附加到该套件上,但是看起来这个测试套件是某种我不想包含在其中的JAR /工具。我的项目。

So I ask: how can I define such a "test suite", consisting of all my test classes, and run all of them in one fell swoop, from inside Eclipse? 因此,我问: 如何定义一个由我所有的测试类组成的“测试套件”,并一口气从Eclipse内部运行所有这些类? Thanks in advance. 提前致谢。

You can right click a project or package in Eclipse and choose to 'Run As->JUnit Test', to run all tests in that project or package. 您可以右键单击Eclipse中的项目或程序包,然后选择“运行方式-> JUnit Test”,以运行该项目或程序包中的所有测试。 No need for a test suite unless you only want to run a subset of the tests. 除非您只想运行测试的子集 ,否则不需要测试套件。

Have you tried to right-click your project and selecting and selecting Run as -> JUnit test? 您是否尝试过右键单击项目,然后选择并选择运行方式-> JUnit测试? That runs all Unittests in the project. 那将运行项目中的所有单元测试。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM