10.1. Overview of Unit test¶
Index
10.1.1. 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.
10.1.2. Unit test guidelines¶
This section explains about methods for implementing tests for layers or between the layers using following OSS libraries.
10.1.2.1. OSS library structure used in unit test¶
10.1.2.1.1. Testing framework¶
JUnit is used as a testing framework of Java.
10.1.2.1.2. Assertion¶
Hamcrest is used as a library to be used in assertion. It is an assertion library supported by JUnit4 as a standard.
10.1.2.1.3. Mocking¶
Mockito is used as a library for mocking the class on which the method to be tested is dependent.
10.1.2.1.4. DI container¶
Di container for test Spring Test DI function is used.
10.1.2.1.5. MVC framework¶
MVC framework for test Spring MVC Test Framework is used.
10.1.2.1.6. Transaction control¶
Spring Test transaction control functionis used as transaction control for test.
10.1.2.1.7. 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 orJdbcTemplate
.
- Spring Test provides a function to execute SQL by using
- 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.
10.1.2.2. 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 OSS Versions.
Tip
From version 5.0.0.RELEASE, a configuration which imports <dependencyManagement>
of
Spring IO platform is adopted.
Dependency relations for following is resolved by importing <dependencyManagement>
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 How to use OSS library used in unit test.
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 |
10.1.2.3. Unit test implementation¶
Unit test is implemented with the following layers in accordance with Application Layering. Test method for layer and test for between the layers is explained in Implementation of test by layer. Common functions that cannot be applied to each layer and function specific test methods are explained in Implementation of tests by functions.
10.1.3. Target readers¶
This section assumes that the readers have following knowledge and experience besides Target readers of this document.
- The user have performed unit test by using JUnit
10.1.4. 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.
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 |