从Eclipse内部运行JUnit测试套件 [英] Running JUnit test suite from inside Eclipse

查看:79
本文介绍了从Eclipse内部运行JUnit测试套件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

从历史上看,我总是这样编写单元测试:

Historically, I've always written my unit tests like this:

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

        // When...

        // Then...
    }
}

这使我可以在Eclipse和Run As >> JUnit中右键单击我的测试文件,并直接从Eclipse内部测试该1个特定测试.然后,在进行本地(基于Ant的)构建时,我配置了<junit> Ant任务以一次运行所有src/test/java测试.

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. 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.

我现在正在寻找一种中间解决方案.也就是说,只需单击一个按钮,即可一次从Eclipse内部运行所有测试类的方法.一位同事建议Junit有一个测试套件"的概念,我可以将所有测试类都附加到该套件上,但是看起来这个测试套件是某种我不想包含在其中的JAR/工具.我的项目.

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. 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.

所以我问:如何定义这样一个由我所有的测试类组成的测试套件",并一口气从Eclipse内部运行所有这些类?在此先感谢您.

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? Thanks in advance.

推荐答案

您可以在Eclipse中右键单击项目或程序包,然后选择运行方式-> JUnit Test",以运行该项目或程序包中的所有测试.除非您只想运行测试的子集,否则不需要测试套件.

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. No need for a test suite unless you only want to run a subset of the tests.

这篇关于从Eclipse内部运行JUnit测试套件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆