sirin05137 / CSE364_Project

2 stars 0 forks source link

[NOTE] JUnit Test Guide & Result #20

Closed yuujinleee closed 3 years ago

yuujinleee commented 3 years ago

Notes ⚠️

Before the Test

Before running the junit test, please edit the Command Prompt print related lines in project.java so that it prints the calculated result with two decimal points only. (This test uses the Command output directly to compare with expected result with ByteArrayOutputStream)

e.g.

System.out.printf("\nThe rating of %s rated by %s : %.2f", genreinput, occupationinput, CalculatedInput); -> System.out.printf("\n%.2f", CalculatedInput); You need to make sure that no other string to be printed out. This is the doc related to ByteArrayOutputStream : Class ByteArrayOutputStream - Oracle doc

Interpretation of Result

When you run the test, you will see 1 failure result for the JUnit Vintage (JUnit 4.X.X). This is because this test imports the modules such as junitparams that only works with JUnit Jupiter (JUnit 5.X.X)

Why this test has commented out?

  1. To shorten the maven building time. This test contains 400-ish test cases. -> This can be solved by adding the option for skipping test in maven surefire plugin but lets consider it from Milestone 2.
  2. For this test, editing the print-related lines in main java file is mandatory. Unless it won't work.
  3. The test has already proven so it's not needed in maven building process.

Test 1 : 1genre 1occupation ALL POSSIBLE CASES (18 genres * 21 occu = 378 cases)

    // --- 1genre 1occupation 모든 조합 결과값 나오나 확인하는 테스트 ---
    // 테스트 결과 pass 기준 : (double)결과값 > 0
    // 총 378 test cases (18 genres * 21 occupation)
    @ParameterizedTest
    @CsvFileSource(resources = "/test1genre.csv", numLinesToSkip = 1)
     public void test1genre(String genre, String occupation, String expected) throws IOException {
        String[] args = new String[2];
        args[0] = genre.toLowerCase().trim();
        args[1] = occupation.toLowerCase().trim();
        project.main(args);

        double result = Double.parseDouble(String.valueOf(outContent));
        assertTrue(result > 0);
    }

Result : It returned calculated output successfully for all 378 cases 👍

Test 2 : Multiple genres (21 cases)

    // --- multiple genres 결과값 맞나 확인하는 테스트 ---
    // 테스트 결과 pass 기준 : (double)결과값 == expected(엑셀손계산)
    // 총 21 test cases
    @ParameterizedTest
    @CsvFileSource(resources = "/testMultiple.csv", numLinesToSkip = 1)
    public void testMultiple(String genre, String occupation, String expected) throws IOException {
        String[] args = new String[2];
        args[0] = genre.toLowerCase().trim();
        args[1] = occupation.toLowerCase().trim();

        project.main(args);
        assertEquals(expected, String.valueOf(outContent));
    }

Result : The calculated result were same with expected value for all 21 cases 👍

yuujinleee commented 3 years ago

About the option for skipping test in maven surefire plugin, please refer to this doc Skipping Tests - Maven Apache Project