Java Unit Test Library-Artery-Sample

■■■■ Java Unit Test Library -Artery- Sample ■■■■

-Introducing a sample of using the Java unit test (Unit test) library Artery that I am developing. This article is the table of contents.

・ Samples will be added one by one.

-Artery also includes an algorithm library. See here. Java Algorithm Library-Artery-Sample

・ The Artery library can be downloaded from the following. Vector ⇒ Programming ⇒ Java Language version202005 --2020/05/13 release

The Artery library can be used free of charge, including for commercial use.

Feature overview

Easy to use (01)

-Easy use of unit test library

Basic judgment processing (02)

Equal value judgment-determines whether two objects have the same value

ArTest.java


  /**Determine if two objects are equal. */
  public static boolean equals(String identifier,String name0,Object value0,String name1,Object value1)
  /**Determine if two objects are not equal. */
  public static boolean notEquals(String identifier,String name0,Object value0,String name1,Object value1) 

Judgment of equality of numerical valuesSequential determination of array ★List,Set ★Map

Same Object Judgment-Judges if two objects are the same object

ArTest.java


  /**Determine if two objects are the same. */
  public static boolean same(String identifier,String name0,Object value0,String name1,Object value1)
  /**Determine if two objects are not the same object. */
  public static boolean notSame(String identifier,String name0,Object value0,String name1,Object value1)

★ [Same object judgment]

Authenticity judgment-Judges whether the specified object is true / false

ArTest.java


  /**Determine if the boolean value is true.*/
  public static boolean isTrue(String identifier,String name,boolean value) 
  /**Determine if the boolean value is true. */
  public static boolean isFalse(String identifier,String name,boolean value)

★ [Authenticity judgment]

Validation-Determine if the specified object matches the ArValidator

ArTest.java


  /**Determine if the object is valid. */
  public static <T> boolean isValid(String identifier,String checkerName,ArValidator<T> checker,String objName,T object)  /**Determine that the object is not valid. */
  public static <T> boolean isNotValid(String identifier,String checkerName,ArValidator<T> checker,String objName,T object)

-Adjustment of objects by ArValidator

Null judgment --Judge whether the specified object is null

ArTest.java


  /**Determine if the object is null. */
  public static boolean isNull(String identifier,String name,Object value)
  /**Determine if the object is null. */
  public static boolean isNotNull(String identifier,String name,Object value)

empty judgment --Judge whether String, Set, List, Map, etc. are empty

ArTest.java


  /**Determine that there is data.The target is the following objects.String,List,Set,Map,ArMapOnMap,ArBiMap,ArMatrix.  */
  public static boolean isNotEmpty(String identifier,String name,Object value)
  /**Determine that there is no data.The target is the following objects.String,List,Set,Map,ArMapOnMap,ArBiMap,ArMatrix. */
  public static boolean isEmpty(String identifier,String name,Object value)

★ [empty judgment]

Success / Fail Declaration-Declare the success / failure of the test

ArTest.java


  /**Declare the success of the test.Return value is always true. */
  public static boolean success(String identifier,String message)
  /**Declare test failure.Return value is always false. */
  public static boolean fail(String identifier,String message)

★[success,fail]

Inclusion determination process (03)

-Determine whether the container (Set, List, array, etc.) contains the specified element. -Determine the inclusion relationship between containers

Element inclusion judgment

ArTest.java


  /**Check if the element is in the Collection. */
  public static <T> boolean contains(String identifier,String nameSet,Collection<T> set,String nameElement,T element)
  /**Determine if the element is in the Collection. */
  public static <T> boolean notContains(String identifier,String nameSet,Collection<T> set,String nameElement,T element)
  /**Determine if the element is in the array. */
  public static <T> boolean contains(String identifier,String nameArray,T[] array,String nameElement,T element)
  /**Determine if the element is not included in the array. */
  public static <T> boolean notContains(String identifier,String nameArray,T[] array,String nameElement,T element)

★ [Collection element inclusion judgment] ★ [Arrangement element inclusion judgment]

Container inclusion judgment

ArTest.java


  /**Check if all the elements of collecitoni B are included in collectioin A. */
  public static <T> boolean contains(String identifier,String nameA,Collection<T> collectionA,String nameB,Collection<T> collectionB)
  /**Determine if any of the elements in collection B are not included in collection A. */
  public static <T> boolean notContains(String identifier,String nameA,Collection<T> collectionA,String nameB,Collection<T> collectionB)
  /**Determine if all the elements of array B are included in array A. */
  public static <T> boolean contains(String identifier,String nameA,T[] arrayA,String nameB,T[] arrayB)
  /**Determine if any of the elements of array B are not included in array A. */
  public static <T> boolean notContains(String identifier,String nameA,T[] arrayA,String nameB,T[] arrayB)
  /**Determine if mapA contains all pairs of mapB. */
  public static <T0,T1> boolean contains(String identifier,String name0,Map<T0,T1> mapA,String name1,Map<T0,T1> mapB)
  /**Determine if any of the elements of mapB are not included in mapA. */
  public static <T0,T1> boolean notContains(String identifier,String name0,Map<T0,T1> mapA,String name1,Map<T0,T1> mapB)

★ [Inclusive judgment between sets] ★ [Containment judgment between arrays] ★ [Inclusive judgment between Maps]

Numerical judgment processing (04)

・ Zero / non-zero judgment ・ Judgment of the size of two numerical values

Zero / non-zero judgment

ArTest.java


  /**Determine if the value is zero.The target is the following types.BigDecimal, Byte, Double, Float, Integer, Long, Short  */
  public static boolean isZero(String identifier,String name,Number value)
  /***Determine if the value is non-zero.The target is the following types.BigDecimal, Byte, Double, Float, Integer, Long, Short */
  public static boolean isNotZero(String identifier,String name,Number value)

Judgment of the magnitude of two numerical values

ArTest.java


  /**Determine if the two numbers are equal.Integer,Long,Float,Double,Supports Big Decimal.Both types may be different. */
  public static boolean equals(String identifier,String name0,Number value0,String name1,Number value1)
  /**Determine if the two numbers are not equal.Integer,Long,Float,Double,Supports Big Decimal.Both types may be different. */
  public static boolean notEquals(String identifier,String name0,Number value0,String name1,Number value1)
  /** value0 <Determine if it is value1.Integer,Long,Float,Double,Supports Big Decimal.Both types may be different. */
  public static boolean lessThan(String identifier,String name0,Number value0,String name1,Number value1)
  /** value0 <=Determine if it is value1.Integer,Long,Float,Double,Supports Big Decimal.Both types may be different. */
  public static boolean lessEqual(String identifier,String name0,Number value0,String name1,Number value1)
  /** value0 >Determine if it is value1.Integer,Long,Float,Double,Supports Big Decimal.Both types may be different. */
  public static boolean greaterThan(String identifier,String name0,Number value0,String name1,Number value1)
  /** value0 >=Determine if it is value1.Integer,Long,Float,Double,Supports Big Decimal.Both types may be different. */
  public static boolean greaterEqual(String identifier,String name0,Number value0,String name1,Number value1)

ArValidator is used for judgment processing other than the above.

-Pass the ArValidator for numerical judgment to the following method and use it.

ArTest.java


  /**Determine if the object is valid. */
  public static <T> boolean isValid(String identifier,String checkerName,ArValidator<T> checker,String objName,T object)
  /**Determine that the object is not valid. */
  public static <T> boolean isNotValid(String identifier,String checkerName,ArValidator<T> checker,String objName,T object) 

Numerical judgment (Q04_00)

Date / time / day of the week judgment processing (05)

-Has the following functions. ・ Current date judgment ・ Current date and time judgment ・ Current day of the week judgment ・ Judgment of designated day of the week ・ Same day judgment

Current date judgment

-Determine whether ArDate, Date, Calendar, and long are the current date.

ArTest.java


  /**Determine if it matches the current date. */
  public static boolean currentDate(String identifier,String name,ArDate date)
  /**Determine if it matches the current date. */
  public static boolean currentDate(String identifier,String name,java.util.Date date)
  /**Determine if it matches the current date. */
  public static boolean currentDate(String identifier,String name,java.util.Calendar cal)
  /**Determine if it matches the current date. */
  public static boolean currentDate(String identifier,String name,long time)

Judgment of current date

Current date and time judgment

-Determine whether Date, Calendar, and long are the current date and time. -Specify the tolerance in minutes.

ArTest.java


  /**Determine if it matches the current date and time.diff is acceptable(Minutes) */
  public static boolean currentTime(String identifier,String name,java.util.Date date,int diff)
  /**Determine if it matches the current date and time.diff is acceptable(Minutes). */
  public static boolean currentTime(String identifier,String name,java.util.Calendar cal,int diff)
  /**Determine if it matches the current date and time.diff is acceptable(Minutes). */
  public static boolean currentTime(String identifier,String name,long time,int diff)

-Determine whether Date, Calendar, long is the current date and time (specify the tolerance in minutes)

Current day of the week judgment

-Determine whether ArDate, Date, Calendar, long, ArYoubi are the current days of the week.

ArTest.java


  /**Determine if it matches the current day of the week. */
  public static boolean currentYoubi(String identifier,String name,ArDate date)
  /**Determine if it matches the current day of the week. */
  public static boolean currentYoubi(String identifier,String name,java.util.Date date)
  /**Determine if it matches the current day of the week. */
  public static boolean currentYoubi(String identifier,String name,java.util.Calendar cal)
  /**Determine if it matches the current day of the week. */
  public static boolean currentYoubi(String identifier,String name,long time)
  /**Determine if it matches the current day of the week. */
  public static boolean currentYoubi(String identifier,String name,ArYoubi youbi)

Judgment of current day of the week (date may be different)-Q05_03

Designated day of the week judgment

-Determine whether ArDate, Date, Calendar, long, ArYoubi are specified days of the week.

ArTest.java


  /**Determine if it matches the specified day of the week. */
  public static boolean youbiEquals(String indentifier,String name,ArDate date,String youbiString,ArYoubi youbi)
  /**Determine if it matches the specified day of the week. */
  public static boolean youbiEquals(String indentifier,String name,java.util.Date date,String youbiString,ArYoubi youbi)
  /**Determine if it matches the specified day of the week. */
  public static boolean youbiEquals(String indentifier,String name,java.util.Calendar cal,String youbiString,ArYoubi youbi)
  /**Determine if it matches the specified day of the week. */
  public static boolean youbiEquals(String indentifier,String name,long time,String youbiString,ArYoubi youbi)
  /**Determine if it matches the specified day of the week. */
  public static boolean youbiEquals(String indentifier,String name,ArYoubi youbi0,String youbiString,ArYoubi youbi1)

Judgment of designated day of the week (regardless of date)

Same day judgment

-Determine whether ArDate, Date, Calendar, and long are on the same day. -Determine whether the day is the same even if the time is different. ・ All the above combinations are available. The following shows the case of Date and Calendar.

ArTest.java


  /**Same day judgment Date vs Calendar. */
  public static boolean sameDate(String identifier,String name0,Date date0,String name1,Calendar cal1)
  /**Non-same day judgment Date vs Calendar. */
  public static boolean notSameDate(String identifier,String name0,Date date0,String name1,Calendar cal1)

-Determine if ArDate, Date, Calendar, long are on the same day

Class judgment

-Determine if two objects are in the same class, -Determine whether the object is of the specified class.

ArTest.java


  /**Determine if two objects are in the same class.  */
  public static boolean sameClass(String identifier,String name0,Object value0,String name1,Object value1)
  /**Determine if two objects are in the same class.  */
  public static boolean notSameClass(String identifier,String name0,Object value0,String name1,Object value1)
  /**Determine if an object is an object of a particular class. */
  public static boolean isThisClass(String identifier,String name0,Object value,String name1,Class clazz)
  /**Determine if an object is an object of a particular class. */
  public static boolean isNotThisClass(String identifier,String name0,Object value,String name1,Class clazz)

★ [Class judgment]

Creating a unit test result report (06)

-The output format should include tab delimiters. ・ It can be used as a test result report by reading it in Excel.

-Automatic unit test result report creation

Execution time measurement (07)

★ [Execution time measurement]

Other (08)

Get a stack trace

★ [Getting stacks and races]

JUnit4 ・ Judgment of equality of numerical valuesSequential determination of array ★ [JUnit4-Judgment of numerical value] ★ [JUnit4-List equality judgment] ★ [JUnit4-List inclusion judgment] ★ [JUnit 4-Set equality judgment] ★ [JUnit 4-Set inclusion judgment] ★ [JUnit 4-Map equality judgment] ★ [JUnit4-Map inclusion judgment] ★ [Various judgments of JUnit4-String] ★ [JUnit4-Authenticity judgment] ★[JUnit4-Success/Fail]

TestNG

Recommended Posts

Java Unit Test Library-Artery-Sample
Java Unit Test Library-Artery-ArValidator Validates Objects
Java Unit Test Library-Artery-Current Date Judgment
Java Unit Test Library-Artery / JUnit4-Array Equivalence
Primality test Java
Java Algorithm Library-Artery-Sample
Java Unit Test Library-Artery / JUnit4-Numerical equality judgment
Java Artery-Easy to use unit test library
Automatic creation of Java unit test result report
Unit test with Junit.
[IntelliJ IDEA] Perform Unit Test
Introduction to Micronaut 2 ~ Unit test ~
Fastest Primality Test C # Java C ++
Java test code method collection
2018 Java Proficiency Test for Newcomers-Basics-
Unit test architecture using ArchUnit
Implementation of unit test code
Java unit tests with Mockito
Implement Table Driven Test in Java 14
test
How to unit test Spring AOP
Execution environment test after Java installation
test
Java
[Rails5] Rspec -Unit test when nesting-
Java SE Bronze exam test content
test
About app testing RSpec (unit test)
test
[Java] Test private methods with JUnit
Significance of existence of unit test (self-discussion)
Java
[RSpec] Unit test (using gem: factory_bot)
Let's unit test with [rails] Rspec!
JUnit unit test pre-processing and post-processing order
[Rails] Unit test code for User model
Introduce RSpec and write unit test code
Java EE test (CDI / interceptor) with Arquillian
I want to write a unit test!
[Java] Test S3 upload / download using "S3 ninja"
Java automated test implementation with JUnit 5 + Gradle
[Java] [Spring] Test the behavior of the logger
Inspect the contents of log output during Java unit test (no mock used)