Automatic creation of Java unit test result report

Table of Contents ⇒ Java Unit Test Library-Artery-Sample

In Java's unit test library Artery, you can make a unit test result report by outputting the unit test results in tab delimiters.

package jp.avaj.lib.test;

/**
Automatic creation of Java unit test result report

If you read the result of the unit test in Excel, you can format it as a test result report.
If this format is acceptable, the trouble of creating a test result report can be saved.

 */
public class Q06_00 {

  public static void main(String[] args) {

    //Creating a unit test result report
    //If you read this output in Excel, it will be a test result report.
    {
      //Excel output specification
      ArTest.testOutLevel = ArTestOutLevel.EXCEL;
      //Test name ⇒ Displayed at the beginning
      ArTestExcelEnv.systemName = "QIITA system unit test result report";
      //Tester ⇒ If not specified, the tester will not be displayed
      ArTestExcelEnv.testerName = "blindly";
      //Test date ⇒ yy if not specified/mm/Become dd
      ArTestExcelEnv.testDate = "12/31";
      //Start of test number ⇒ 0 if not specified
      ArTestExcelEnv.startTestNo = 1;
    }

    //Specifying the log output file
    ArTest.startUnitTest("unittest","c:/tmp");


    ArTest.startTestCase("Leap year judgment");

    boolean result;
    //2020 is a leap year ⇒ result is true
    result = LeapYear.isLeapYear(2020);
    //Check the result.
    ArTest.isTrue("2020","result",result);

    //2100 is a normal year ⇒ result is correct to false
    result = LeapYear.isLeapYear(2100);
    //Check the result.
    ArTest.isFalse("2100","result",result);

    //End the test case
    ArTest.endTestCase();


    ArTest.startTestCase("Kim Basinger's role name ⇒ movie name conversion");

    //Vicky Vale ⇒ The correct answer is Batman
    String movie = Kim.getMovieTitle("Vicky Vale");
    //Check the result
    ArTest.equals("Vicky Vale","expected","Batman","movie",movie);

    //Carol McCoy ⇒ The correct answer is Getaway
    movie = Kim.getMovieTitle("Carol McCoy");
    //Check the result
    ArTest.equals("Carol McCoy","expected","Getaway","movie",movie);

    //End the test case
    ArTest.endTestCase();


    //View aggregates for all test cases
    ArTest.reportTotalSummary();

  }
  ////////////The following is the class to be tested
  /**Leap year judgment class(Maybe there is a bug). */
  static class LeapYear {
    public static boolean isLeapYear(int year) {
      return ((year % 4) == 0);
    }
  }
  /**Kim Basinger's role name ⇒ movie name conversion class(Maybe there is a bug). */
  static class Kim {
    public static String getMovieTitle(String name) {
      if ("Vicky Vale".equals(name)) { return "Batman"; }
      if ("Carol McCoy".equals(name)) { return "Blondie"; }
      //Others omitted
      return null;
    }
  }
}

The result when the output of Excel is not specified is as follows.

result.txt


****Leap year judgment start****
OK 2020:result=true
NG 2100:result=true
jp.avaj.lib.test.Q06_00.main(Q06_00.java:44)
****Leap year judgment summary****
test count = 2
success    = 1
****Kim Basinger's role name ⇒ movie name conversion start****
OK Vicky Vale:expected=Batman:movie=Batman
NG Carol McCoy:expected=Getaway:movie=Blondie
jp.avaj.lib.test.Q06_00.main(Q06_00.java:60)
****Kim Basinger's role name ⇒ movie name conversion summary****
test count = 2
success    = 1
**** total ****
total test count = 4
total success    = 2

The result when the output of Excel is specified is as follows.

result.txt



QIITA system unit test result report

****Leap year judgment start****
TestNo Date Responsible result Test content Expected value Actual value
001-001	12/31 Dark clouds OK 2020 TRUE true
001-002	12/31 Dark Cloud NG 2100 FALSE true
****Leap year judgment summary****
test count = 2
success    = 1
****Kim Basinger's role name ⇒ movie name conversion start****
TestNo Date Responsible result Test content Expected value Actual value
002-001	12/31 Dark Clouds OK Vicky Vale Batman Batman
002-002	12/31 Dark Clouds NG Carol McCoy Getaway Blondie
****Kim Basinger's role name ⇒ movie name conversion summary****
test count = 2
success    = 1
**** total ****
total test count = 4
total success    = 2

When read in Excel, it becomes as follows.

無題.png

Recommended Posts

Automatic creation of Java unit test result report
I checked the automatic unit test creation tool (end of 2019 version)
Java Unit Test Library-Artery-Sample
[Java] Creation of original annotation
Implementation of unit test code
Java Unit Test Library-Artery-ArValidator Validates Objects
Java Unit Test Library-Artery-Current Date Judgment
Significance of existence of unit test (self-discussion)
Java Unit Test Library-Artery / JUnit4-Array Equivalence
[Java] From new project creation to automatic test / build / deployment realization
Get the result of POST in Java
Java Unit Test Library-Artery / JUnit4-Numerical equality judgment
Introduction memo of automatic test using Jenkins
Java Artery-Easy to use unit test library
[Java] [Spring] Test the behavior of the logger
Inspect the contents of log output during Java unit test (no mock used)
Story of test automation using Appium [Android / java]
Primality test Java
java file creation
java directory creation
[Java] Overview of Java
RSpec unit test code creation procedure (login user creation Ver.)