1
我是新手。我正在进行JUnit测试。以下是我测试的内容:我有一个包含记录列表的输入文件。如果记录有电子邮件,我必须将其添加到我的输出文件中,名为myemailfile.txt检查某个记录是否在文件中
在我的JUnit测试中,我必须测试带有[email protected]的人是否包含在myemailfile.txt中
有人可以请告知如何通过该文件,并检查这样的记录是否使它到文件。
Here is my file:
First Name,Last Name,Email,Id
John ,Dough ,[email protected] ,12345
Jane ,Smith ,[email protected] ,86547
Mary ,Wells ,[email protected] ,76543
以下是我的测试
@Test
public void isRecordIncludedInEmailFile() throws IOException{
String testFile = "C:/Users/myname/myemailfile.txt";
BufferedReader br = null;
String line = "";
String fileSplitBy = ",";
try {
br = new BufferedReader(new FileReader(testFile));
while ((line = br.readLine()) != null) {
// use comma as separator
String[] field = line.split(fileSplitBy);
//read through the file and see if the email that I expect ([email protected]) exists in the file
System.out.println("Email [email= " + field[2] + " , first name=" + field[0] + "]");
//the line below should assert if "[email protected]" exists in the file
// assertEquals("[email protected]", field[2]);
}
谢谢