Я новичок. Я работаю над тестом 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]);
}
Спасибо