In the Package Explorer view, select the JUnit project. Click the New Java Package button in the toolbar, or select New > Package from the project's context menu .
在包管理器视图中选择JUnit工程,点击工具栏中的New Java Package 按钮,或右键选择New > Package菜单。
In the Name field, type test as the name for the new package. Then click Finish.
在Name 输入框输入test,点击Finish按钮。
In the Package Explorer view, select the new test package and click the New Java Class button in the toolbar.
选择test包,点击工具栏中的New Java Class 按钮,或右键选择New > Class菜单。
Make sure that JUnit appears in the Source Folder field and that test appears in the Package field. In the Name field, type MyTestCase.
确认Source Folder和Package输入框中的内容,并在Name 输入框中输入MyTestCase。
Click the Browse button next to the Superclass field.
点击Superclass 输入框右边的Browse 按钮。
In the Choose a type field in the Superclass Selection dialog, type Test to narrow the list of available superclasses.
在Choose a type输入框中输入test。
Select the TestCase class and click OK.
选择TestCase 类,然后点击OK。
Select the checkbox for Constructors from superclass.
勾选Constructors from superclass复选框。
Click Finish to create the new class.
点击Finish 按钮。
The new file is opened in the editor. It contains the new class, the constructor and comments. You can select options for the creation and configuration of generated comments in the Java > Code Style > Code Templates preference page.
新创建的文件会在编辑器中打开,它包含了新的类、构造器和注释。你可以在Java > Code Style > Code Templates首选页中更改类创建和注释的配置信息。
In the Outline view select the new class MyTestCase. Open the context menu and select Source > Override/Implement Methods....
在Outline视图中选择MyTestCase类,右键选择Source > Override/Implement Methods…菜单。
In the Override Methods dialog, check setUp() and tearDown() and click OK. Two methods are added to the class.
在弹出的对话框中,勾选setUp() 和tearDown()并点击OK。
Change the body of setUp() tocontainer= new Vector();
把setUp() 方法体改成container= new Vector();
container and Vector are underlined with a problem highlight line as they cannot be resolved. A light bulb appears on the marker bar. Move the mouse over the underlined word Vector. A hover appears that shows the error message and contains quick fixes. Move the mouse into the hover and clickImport 'Vector' (java.util). This adds the missing import declaration.
container 和Vector 因无法被解析而高亮显示,同时,左侧标记栏出现电灯泡记号,把鼠标悬停在Vector 上会出现错误提示以及快速修复建议,选择Import 'Vector' (java.util)。
The blinking cursor should still be on the line that contains the error (if not, set it to the end of the line). PressCtrl+1. This lets the cursor jump to the nearest error location and opens the quick fix proposals. Choose Create field 'container' to add the new field.
闪烁的光标所在行仍然有错,按下Ctrl+1快捷键(并不能跳到container错误处,需手动将光标移动到container上) ,在弹出的快速修复建议中选择Create field 'container' 。
In the Outline view, select the class MyTestCase. Open the context menu and select Source > Generate Getters and Setters....
在Outline视图中,选择MyTestCase类右键Source > Generate Getters and Setters…菜单。
The Generate Getter and Setter dialog suggests that you create the methods getContainer and setContainer. Select both and click OK. A getter and setter method for the field container are added.
弹出对话框建议创建getContainer 和setContainer方法,都勾选然后点击OK按钮。
Save the file.
保存文件。
The formatting of generated code can be configured in the Java > Code Style > Formatter preference page. If you use a prefix or suffix for field names (e.g. fContainer), you can specify this in the Java > Code Style preference page so that generated getters and setters will suggest method names without the prefix or suffix.
自动生成的代码格式可以在Java > Code Style > Formatter 首选页中配置,如果你喜欢为field加上前缀或者后缀,可以在Java > Code Style 首选页中配置,默认生成的getters 和setters 是没有前后缀的。