Overview of Unit test ================================================================================ .. only:: html .. contents:: Index :local: Introduction -------------------------------------------------------------------------------- This section explains about unit test using JUnit, in a system using TERASOLUNA Server Framework (5.x). Scope of unit test is considered as layer or interlayer coupling. Test execution and test implementation will be explained out of all the test activities. Note that, the test implementation explained here is a reference example and the test policy for ensuring system quality should be considered separately. Unit test guidelines -------------------------------------------------------------------------------- This section explains about methods for implementing tests for layers or between the layers using following OSS libraries. OSS library structure used in unit test ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Testing framework """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" \ `JUnit `_\ is used as a testing framework of Java. Assertion """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" \ `Hamcrest `_\ is used as a library to be used in assertion. It is an assertion library supported by JUnit4 as a standard. Mocking """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" \ `Mockito `_\ is used as a library for mocking the class on which the method to be tested is dependent. DI container """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" Di container for test \ `Spring Test DI function `_\ is used. MVC framework """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" MVC framework for test \ `Spring MVC Test Framework `_\ is used. Transaction control """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" \ `Spring Test transaction control function `_\ is used as transaction control for test. Data access """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" Spring Test or DBUnit and Spring Test DBUnit are assumed to be used for data access of test. * \ `Spring Test `_\ * Spring Test provides a function to execute SQL by using \ ``@Sql``\ annotation or \ ``JdbcTemplate``\. * \ `DBUnit `_\ and \ `Spring Test DBUnit `_\ * Spring Test DBUnit is a support library for using DBUnit on Spring Framework and hence used in combination with DBUnit. It provides function to implement functions like database setup and status verification provided by DBUnit. Version of OSS library to be used in unit test ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ List of OSS libraries used in unit test are shown below. Note that, following OSS libraries are only examples and the library suited to the actual business requirement must be considered. Further, for OSS libraries used to operate application itself in this section, refer \ :ref:`frameworkstack_using_oss_version`\. .. tip:: From version 5.0.0.RELEASE, a configuration which imports \ ````\ of \ `Spring IO platform `_\ is adopted. Dependency relations for following is resolved by importing \ ````\ of Spring IO platform * Library provided by Spring Framework * OSS library on which Spring Framework is dependent * OSS library compatible with Spring Framework OSS version used in TERASOLUNA Server Framework (5.x), as a rule, conforms to definition of Spring IO platform. Note that, version of Spring IO platform specified in version 5.4.1.RELEASE is \ `Brussels-SR5 `_\. | Among the OSS libraries below, for how to use Spring Test (MockMvc) and Mockito, refer \ :ref:`UsageOfLibraryForTest`\. .. tabularcolumns:: |p{0.20\linewidth}|p{0.25\linewidth}|p{0.20\linewidth}|p{0.15\linewidth}|p{0.20\linewidth}| .. list-table:: :header-rows: 1 :widths: 20 25 20 15 20 * - Type - GroupId - ArtifactId - Version - Spring IO platform * - JUnit - junit - junit - 4.12 - \* * - Hamcrest - org.hamcrest - hamcrest-core - 1.3 - \* * - Hamcrest - org.hamcrest - hamcrest-library - 1.3 - \* * - Mockito - org.mockito - mockito-core - 1.10.19 - \* * - Spring Test - org.springframework - spring-test - 4.3.14.RELEASE - * - DBUnit - org.dbunit - dbunit - 2.5.4 - \ * - Spring Test DBUnit - com.github.springtestdbunit - spring-test-dbunit - 1.3.0 - \ | Unit test implementation ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Unit test is implemented with the following layers in accordance with \ :ref:`ApplicationLayering`\. Test method for layer and test for between the layers is explained in \ :ref:`ImplementsOfTestByLayer`\. Common functions that cannot be applied to each layer and function specific test methods are explained in \ :ref:`ImplementsOfTestByFunction`\. .. figure:: ./images/UnitTestOverviewApplicationLayer.png :width: 85% | Target readers -------------------------------------------------------------------------------- This section assumes that the readers have following knowledge and experience besides \ :ref:`TargetReadersOfThisDocument`\. * The user have performed unit test by using JUnit Operation verification environment of unit test -------------------------------------------------------------------------------- This section explains operation verification in the following environment. While implementing on other environments, it should be read appropriately considering this section as base. .. tabularcolumns:: |p{0.25\linewidth}|p{0.75\linewidth}| .. list-table:: :header-rows: 1 :widths: 25 75 * - Type - Name * - OS - Windows 7 * - JVM - `Java `_ 1.8.0_144 * - IDE - `Spring Tool Suite `_ 3.9.1.RELEASE (hereafter called as "STS") * - Build Tool - `Apache Maven `_ 3.3.9 (hereafter called as "Maven") * - RDBMS - `PostgreSQL `_ 9.6.5