下载此文档

Linux下用intellij idea使用JUnit进行代码单元测试.docx


文档分类:IT计算机 | 页数:约5页 举报非法文档有奖
1/5
下载提示
  • 1.该资料是网友上传的,本站提供全文预览,预览什么样,下载就什么样。
  • 2.下载该文档所得收入归上传者、原创者。
  • 3.下载的文档,不会出现我们的网址水印。
1/5 下载此文档
文档列表 文档介绍
Linux下用Intellij idea使用JUnit进行代码单元测试
今天看了一下《Java开放源码编程》一书,在intellij idea上进行了平生首个JUnit代码单元测试,步骤如下:
.test下建立三个测试类,xcl文件加下面建立两个类并被用于测试,其中TestParser是CsvPaser的测试类,TestTelephoneBook是TelephoneBook的测试类,使用MyTestSuite测试类可以一次执行所有的测试。
2编写代码如下:
:
.xcl;
import ;
/**
* Created by xcl on 15-12-24.
*/
public class CsvPaser {
private String[] currentLine;
public void parse(String input){
StringTokenizer tokenizer=new StringTokenizer(input,",");
currentLine=new String[()];
for(int i=0;i<;i++){
currentLine[i]=();
}
}
public String get(int columnIndex){
return currentLine[columnIndex];
}
}
:
.xcl;
import ;
import ;
/**
* Created by xcl on 15-12-24.
*/
public class TelephoneBook {
public Map<String,String> map=new HashMap<String,String>();
public TelephoneBook(Map<String,String>map){
=map;
}
public String getTelephone(String name){
return (name);
}
}
:
.test;
.;
import ;
import ;
.;
/**
* Created by xcl on 15-12-24.
*/
public class TestParser extends TestCase{
***@Test
public void testParseSimpleLine(){
CsvPaser paser=new CsvPaser();
("Bill, Gates, 555

Linux下用intellij idea使用JUnit进行代码单元测试 来自淘豆网m.daumloan.com转载请标明出处.

非法内容举报中心
文档信息
  • 页数5
  • 收藏数0 收藏
  • 顶次数0
  • 上传人xunlai783
  • 文件大小104 KB
  • 时间2018-01-07