简体   繁体   English

从 java 类自动生成 jUnit 类

[英]Generate automatically a jUnit class from a java class

I just want to know if there is a tool or a function on right click to generate automatically a jUnit class when we've created a basic java class ?我只想知道当我们创建一个基本的java类时,是否有一个工具或一个函数可以在右键单击时自动生成一个jUnit类?

Because I think I've already done this... But I can not remember how.因为我想我已经这样做了......但我不记得是怎么做的。

IDE: Eclispe Mars. IDE:Eclispe Mars。

Thanks !谢谢 !

Just select a class and go for : New->JUnit test case只需选择一个类并执行:New->JUnit test case

Eclipse will ask you to checkbox all methods you want to test, and give you a nice configuration wizard, import junit etc... Eclipse 会要求您选中所有要测试的方法,并为您提供一个不错的配置向导,导入 junit 等...

Some Eclipse versions (I don't remember in which one I saw it) if you right click on the class name, it shows "Create JUnit test case for this class" in the context menu.某些 Eclipse 版本(我不记得我在哪个版本中看到过)如果您右键单击类名,它会在上下文菜单中显示“为该类创建 JUnit 测试用例”。 But in some others it does not do that.但在其他一些情况下,它不会这样做。 You can a key short cut for it.你可以为它设置一个关键的捷径。

Head to Window --> Preferences --> General --> Keys and search for junit.前往 Window --> Preferences --> General --> Keys 并搜索 junit。 Then you can easily add the shortcut you want to:然后您可以轻松添加您想要的快捷方式:

在此处输入图片说明

You can download any of plugin for this like MoreUnit or JUnitRunner.您可以为此下载任何插件,例如 MoreUnit 或 JUnitRunner。 Eclipse itslf, has build it JUnit tool. Eclipse 本身,已经构建了 JUnit 工具。 You can follow below steps: 1. Select a java file.您可以按照以下步骤操作: 1. 选择一个 java 文件。 2. Right click -> New... --> JUnit Test Case 3. Next-> Select method to test 2. 右击 -> New... --> JUnit Test Case 3. Next-> Select method to test

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

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