[英]How do I assert that when I put in two string inputs that a specific array is output JUnit testing
Hey guys I have a problem, I would like to assert that when I input 2 specific strings that an array is returned. 嗨,我有一个问题,我想断言,当我输入2个特定的字符串时,会返回一个数组。 I want to use the assert statement and parameterized testing to do this however my current assert statement is showing an error , I have placed my code below please help:
我想使用assert语句和参数化测试来执行此操作,但是我当前的assert语句显示错误 ,我将代码放在下面,请帮助:
My inputs are both String data type and my output from the drop course is an array 我的输入都是String数据类型,而我的下拉课程的输出是一个数组
import IT_chatbot.drop_course;
@RunWith(Parameterized.class)
public class drop_course_test {
drop_course check;
@Before
public void setUp() throws Exception {
check= new drop_course();
}
private String[] output;
private String input1;
private String input2;
public drop_course_test(String output[],String input1,String input2 )
{
this.output=output;
this.input1=input1;
this.input2=input2;
}
@Parameters
public static Collection testConditions(){
String[] droplist1={"ITE222 Web Development 2","ITE365 Software Quality Management","ITE446 Current Topics in Software Engineering","ITE220 Programming 1"};
return Arrays.asList(new Object [][]{
{droplist1, "216110116","ITE200"},
});
}
@Test
public void test() {
assertEquals(output, drop_course.drop(input1, input2));
}
}
The method i am trying to test can be seen below: 我正在尝试测试的方法可以在下面看到:
package IT_chatbot;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
public class drop_course {
public static String[] drop(String studentID, String courseCode){
String filePath = "enrolled_courses"+studentID+".txt";
String disenrolled_subtracted[]=new String[5];
int value_at=0;
System.out.println("Your Course has been dropped the following are your current courses:");
try {
BufferedReader lineReader = new BufferedReader(new FileReader(filePath));
String lineText = null;
while ((lineText = lineReader.readLine()) != null) {
if(lineText.contains(courseCode)){
lineText = lineText.replace(lineText, "");
FileWriter writer = new FileWriter("filePath", true);
writer.write("-disenrolled-"+lineText);
}else{
System.out.println(lineText);
disenrolled_subtracted[value_at]=lineText;
value_at=value_at+1;
}
}
lineReader.close();
} catch (IOException ex) {
System.err.println(ex);
}
return disenrolled_subtracted;
}
Use Method 使用方法
Assert.assertArrayEquals( expectedResult, result );
Instead of 代替
assertEquals
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.