简体   繁体   English

如何在Eclipse中创建单元测试项目?

[英]How to create a unit test project in Eclipse?

I have experience with Visual Studio but very new to Eclipse. 我有使用Visual Studio的经验,但是对Eclipse还是很新的。 In Visual studio, you can easily create a unit test project for an existing production project. 在Visual Studio中,您可以轻松为现有生产项目创建单元测试项目。 In this way, test code and production code are in separate places. 这样,测试代码和生产代码位于不同的位置。

How can I do this in Eclipse? 如何在Eclipse中执行此操作? Didn't see a Unit Test project in the New wizard dialog. 在“新建”向导对话框中没有看到单元测试项目。

File -> New -> JUnit Test Case 文件->新建-> JUnit测试用例

在此处输入图片说明

In Java development common practices, instead of creating a separate project for unit tests, we usually put unit tests together with the project itself. 在Java开发的通用实践中,我们通常不会将单元测试与项目本身放在一起,而不必为单元测试创​​建单独的项目。 Unit tests are normally put under a separate directory so it can be easily compiled and run, and be excluded when creating the final artifact. 单元测试通常放在单独的目录下,因此可以轻松地进行编译和运行,并且在创建最终工件时将其排除在外。

Apart from File -> New -> Junit test case mentioned in another answer, there are other way to create new tests, for example, by right-clicking the class that you want to test against. 除了另一个答案中提到的File -> New -> Junit test case ,还有其他创建新测试的方法,例如,通过右键单击要测试的类。

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

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