简体   繁体   English

我如何断言当我输入两个字符串输入时,特定的数组正在输出JUnit测试

[英]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.

相关问题 我如何断言我的方法返回一个特定的数组 - junit how would I assert that my method returns a specific array 如何将JUnit输出分配给String? - How do I assign JUnit output to a String? 如何在数组/ arraylist中存储多个用户输入(String,Int,Double)并输出存储的数据(Java)? - How do i store multiple user inputs (String,Int,Double) in an array/arraylist and output the stored data(Java)? 如何使用 JUnit 测试批注断言我的异常消息? - How do I assert my exception message with JUnit Test annotation? 如何使用JUnit Test注释声明IOException消息? - How do I assert an IOException message with JUnit Test annotation? 如何为获得的两个输出留出一些空间? - How do i put some space for the two output i obtained? 如果我没有实现Junit测试用例,可以在Junit中使用Assert类吗? - Can I use Assert class in Junit if I am not implementing Junit test cases and how to do that? 当我用JUnit测试时,如何声明Spring属性占位符? - When I am testing with JUnit how do I declare the Spring property place holder? 如何将String放入数组,然后放入double数组? - How do I put a String into an array and then into an array of double? jUnit 测试:尝试编写一个测试,我可以在其中输入空字符串到 function 并且我想断言返回值为 null - jUnit Testing: Trying to write a test where I can input empty string to the function and I want to assert that the return value is null
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM