Test Development Learning

1. Trends in software quality

Modern Software Development Model

The problem with the traditional waterfall model is that the delivery cycle is too long for the needs of users, and the agile model breaks a big problem into many small problems.

Each iteration emphasizes delivering local value, which is also called MVP Minimum Delivery Value. It is difficult to select MVP

A compromise "pseudo" agile test

By automating the testing process to keep up with the speed required for delivery, the first step is required for testers to program. Secondly, due to the simplification of the Internet in the current business, the technical requirements for R&D personnel are much higher than for business, and the matching testing technology is also skewed, which results in testers having greater technical requirements than business personnel.

Continuous integration, continuous publishing, and continuous delivery have become the technical solution to the R&D end based on DevOps. The disadvantage of such DevOps is that it does not introduce the demand side, but it achieves fast debugging in the R&D area assuming that the demand is an MVP, which is implemented quickly in the delivery R&D area and handed over to users for quick debugging.

Common delivery modes are as follows, and at this end, to improve the efficiency of testing, test is divided into tests, which is born. Layered testing is designed in the technical domain and requires a lot of R&D, so test development skills stack is born.


Generate test methods

Add JUINT5 Dependency

<!-- https://mvnrepository.com/artifact/org.junit.jupiter/junit-jupiter-api -->

1. Select method, right-click

2. Select test


3. Select OK

Drivers and Assertions

class ResultCodeTest {

    void setCode() {

    void Code200(){
        ResultCode expected = ResultCode.OK;
        // Use assertions to judge
        Assertions.assertEquals(expected.getCode(),200,"Assert 200 Status");

Complete some initialization or destruction operations before and after test execution because the framework creates a separate instance for each test, and no test instances are created when the @BeforeAll / @AfterAll method is executed. Therefore, these two methods must be defined as static methods

- @BeforeAll executes only once, before all tests and @BeforeEach annotation methods

- @BeforeEach is executed before each test execution (Juint4 is @Before)

- @AfterEach is executed after each test execution (Junit4 is @After)

- @AfterAll executes only once, after all tests and @AfterEach annotation methods

Based on SpringBootTest

Used to test DAO and sevice layers, direct JUNIT testing will fail

Test impl

Select queryById generation test method

Annotate @SpringBootTest on the Test class

Inject UserServiceimpl


Write test logic

class UserServiceImplTest {
    private UserService userService;

    void queryById() {
        User myu = new User();
        myu = this.userService.queryById(1);

Test success:

Test Failure: Change cloud to cloud 1

Test the insertion function:

    void insertUser(){
        User myu = new User();

Execution Result: Successful execution

View Database: Insert Successful

Disadvantage: True insertion of data into the database


Method with @Transactional annotation means that it uses transactions and rolls back automatically after each execution

If you don't want to rollback, you can add @Rollback(false) to the method, which is true by default

Re-execute the above method: Change 13 to 14 to execute

View the database:

No data inserted into the database

Tags: unit testing

Posted on Tue, 21 Sep 2021 12:07:29 -0400 by RHolm