Liny_@NotePad

沉迷ACG中

Eclipse生成JUnit Test Case

YOYO posted @ 2009年6月30日 03:10 in 【工具/OS】 with tags Eclipse , 5165 阅读

在BlogJava上看到,翻写~首先写好一个随便什么类 = =

  1. /**
  2. * User Action
  3. * @author YOYO
  4. */
  5. public class UserAction {
  6.        
  7.         public int add(int a, int b){
  8.                 return a+b;
  9.         }
  10.        
  11.         public int minus(int a, int b){
  12.                 return a-b;
  13.         }
  14.  
  15. }
  16.  

在类文件名上右键 选择 New -> JUnit Test Case

设定测试类的src、package和类名:

设定要测试的方法

如果Project中没有导入JUnite的Library,它会提示你导入:

单击OK后就生成了如下的测试类:

  1. package test;
  2.  
  3. import junit.framework.TestCase;
  4.  
  5. public class UserActionTest extends TestCase {
  6.  
  7.         public void testAdd() {
  8.                 fail("Not yet implemented");
  9.         }
  10.  
  11.         public void testMinus() {
  12.                 fail("Not yet implemented");
  13.         }
  14.  
  15. }

这样我们只需要填写方法的内容即可 = =。


登录 *


loading captcha image...
(输入验证码)
or Ctrl+Enter