Table of Contents ⇒ Java Unit Test Library-Artery-Sample
package jp.avaj.lib.test;
/**
Easy to use unit test library
-Although there are other test methods, the following method usage examples are introduced as the most frequent ones..
・ IsTrue ⇒ Determine if the given argument is true.
・ IsFalse ⇒ Determine if the given argument is false.
・ Equals ⇒ Determine if the two given arguments are equal.
-Although the following method was also used in this usage example, it is not necessary to use it when using it for debugging.
・ StartUnitTest
・ StartTestCase
・ EndTestCase
・ ReportTotalSummary
 */
public class Q01_00 {
  public static void main(String[] args) {
    //Do not display message ⇒ Note, only summary is displayed
    //I will comment this time
    // ArTest.testOutLevel = ArTestOutLevel.NONE;
    //Stop when NG occurs.
    //I will comment this time.
	// ArTest.testIfError = ArTestIfError.ABORT;
    /*
・ Start unit test.
-Use when you want to output the log to a file, unnecessary if you just display it on the screen
-Specify the test name and log output directory.
-The test name becomes part of the log file name.
・ Create a directory in advance.
     */
    ArTest.startUnitTest("unittest","c:/tmp");
    //Start test case, OK/Not needed if you don't need NG statistics
    ArTest.startTestCase("Leap year judgment class test");
    boolean result;
    //2020 is a leap year ⇒ result is true
    result = LeapYear.isLeapYear(2020);
    /*
・ Check the result.
-The first argument describes the purpose and content of the test,Comment on the library.
・ The second argument describes the name of the variable you want to judge..Comment on the library.
・ The third argument describes the variable you want to judge..
     */
    ArTest.isTrue("2020","result",result);
    //2100 is a normal year ⇒ result is correct to false
    result = LeapYear.isLeapYear(2100);
    /*
・ Check the result.
-The first argument describes the purpose and content of the test,Comment on the library.
・ The second argument describes the name of the variable you want to judge.,Comment on the library.
・ The third argument describes the variable you want to judge..
・ In case of NG, the line number is displayed.
    */
    ArTest.isFalse("2100","result",result);
    //
    //End the test case ⇒ The total in the test case is displayed, unnecessary if startTestCase is not done
    ArTest.endTestCase();
    L.p("");
    //Start test case, OK/Not needed if you don't need NG statistics
    ArTest.startTestCase("Kim Basinger's role name ⇒ movie name conversion class test");
    //Vicky Vale ⇒ The correct answer is Batman
    String movie = Kim.getMovieTitle("Vicky Vale");
    /*
・ Check the result
-The first argument describes the purpose and content of the test,Comment on the library.
-The second argument is the variable name of the expected value.,Comment on the library.⇒Since the expected value is described directly here"expected"Designated as
・ The argument of the third name is the expected value
・ The argument of the fourth name is the variable name of the variable you want to judge..,Comment on the library.
・ The argument of the fifth name is the variable you want to judge
     */
    ArTest.equals("Vicky Vale","expected","Batman","movie",movie);
    //Carol McCoy ⇒ The correct answer is Getaway
    movie = Kim.getMovieTitle("Carol McCoy");
    /*
・ Check the result
-The first argument describes the purpose and content of the test,Comment on the library.
-The second argument is the variable name of the expected value,Comment on the library.⇒Since the expected value is described directly here"expected"Designated as
・ The argument of the third name is the expected value
・ The argument of the fourth name is the variable name of the variable you want to judge.,Comment on the library.
・ The argument of the fifth name is the variable you want to judge
・ In case of NG, the line number is displayed.
・ The role name in Blondie is Karen McCoy.
     */
    ArTest.equals("Carol McCoy","expected","Getaway","movie",movie);
    //End the test case ⇒ The total in the test case is displayed, unnecessary if you do not need the total data
    ArTest.endTestCase();
    L.p("");
    //Display of aggregates of all test cases, unnecessary if aggregated data is not needed
    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 is as follows.
result.txt
****Leap year judgment class test start****
OK 2020:result=true
NG 2100:result=true
jp.avaj.lib.test.Q01_00.main(Q01_00.java:63)
****Leap year judgment class test summary****
test count = 2
success    = 1
****Kim Basinger's role name ⇒ movie name conversion class test start****
OK Vicky Vale:expected=Batman:movie=Batman
NG Carol McCoy:expected=Getaway:movie=Blondie
jp.avaj.lib.test.Q01_00.main(Q01_00.java:97)
****Kim Basinger's role name ⇒ movie name conversion class test summary****
test count = 2
success    = 1
**** total ****
total test count = 4
total success    = 2
        Recommended Posts