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

查看:18
本文介绍了如何从 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 Web 应用程序的菜单选项不同.所以本教程中的说明并不普遍适用.

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.

您还可以通过右键单击源文件然后工具 > 创建 JUnit 测试"让 NetBeans 为您自动生成测试.

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天全站免登陆