简体   繁体   中英

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. 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:

My inputs are both String data type and my output from the drop course is an array

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM