如何从NetBeans运行JUnit? [英] How do I run JUnit from NetBeans?

查看:336
本文介绍了如何从NetBeans运行JUnit?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在努力了解如何开始编写和运行JUnit测试。

I've been trying to understand how to start writing and running JUnit tests.

当我读这篇文章时:

http://junit.sourceforge.net/doc/testinfected/ testing.htm

我得到了页面的中间部分,他们写道,JUnit带有一个图形界面来运行测试。输入你的名字在窗口顶部的字段中测试类。按运行按钮。

I get the the middle of the page and they write, "JUnit comes with a graphical interface to run tests. Type the name of your test class in the field at the top of the window. Press the Run button."

我不知道如何启动此程序。我甚至不知道它在哪个包中,或者你如何从IDE运行库类。

I don't know how to launch this program. I don't even know which package it is in, or how you run a library class from an IDE.

陷入困境,我尝试了这个NetBeans教程:

Being stuck, I tried this NetBeans tutorial:

http://www.netbeans.org/kb/docs/java/junit-intro.html

似乎没问题,但后来我注意到本教程中用于测试Java类库的菜单选项与常规Java应用程序或Java的不同网络应用。所以本教程中的说明一般不适用。

It seemed to be going OK, but then I noticed that the menu options for this tutorial for testing a Java Class Library are different from those for a regular Java application, or for a Java Web App. So the instructions in this tutorial don't apply generally.

我正在使用NetBeans 6.7,我已将JUnit 4.5导入库文件夹。编写测试后,运行JUnit的正常方法是什么?

I'm using NetBeans 6.7, and I've imported JUnit 4.5 into the libraries folder. What would be the normal way to run JUnit, after having written the tests?

JUnit FAQ从控制台描述了该过程,我愿意这样做,如果这是典型的,但考虑到我可以在netbeans中做的所有事情,似乎很难相信没有更简单的方法。

The JUnit FAQ describes the process from the Console, and I'm willing to do that if that is what is typical, but given all that I can do inside netbeans, it seems hard to believe that there isn't an easier way.

非常感谢。

编辑:如果我右键单击项目并选择测试,则输出为:

If I right-click on the project and select "Test" the output is:

init:
deps-jar:
compile:
compile-test:
test-report:
test:
BUILD SUCCESSFUL (total time: 0 seconds)

这不会打击我测试的期望输出,特别是因为这不会改变测试条件是否为真。

This doesn't strike me as the desired output of a test, especially since this doesn't change whether the test condition is true or not.

任何想法?

推荐答案

一种方法是在项目窗格中右键单击项目,然后选择测试。那将运行JUnit测试。您也可以右键单击测试文件并选择运行测试,然后运行该单个文件。键盘快捷键取决于您如何设置键盘映射,但您可以在上下文菜单中看到它们。

One way is to right click on your project in the Projects pane and select "Tests". That will run the JUnit tests. You can also right click on the test file and select "Run Test" and that single file will be ran. The keyboard shortcuts depends on how you have your keymapping set, but you'll see them in the context menus.

您也可以通过右键单击为您自己生成NetBeans自动生成测试您的源文件,然后工具>创建JUnit测试。

You can also have NetBeans autogenerate tests for you by right clicking your source file and then "Tools > Create JUnit Tests".

这篇关于如何从NetBeans运行JUnit?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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