This article has participated in the third “High Yield more text” track of the Denver Creators Training Camp, check out the details:Digg project | Creator Boot Camp phase 3 is underway, “write” to make a personal impact.

background

Due to the tight development schedule and incomplete interface and basic data, even comprehensive interface test cases can not be fully and effectively covered test; And because the direction of single-interface test case design is input parameter and output parameter, starting from input parameter is required parameter verification, parameter type and parameter boundary value, and then the combination of input parameters, for example, an interface has 5 parameters, 3 mandatory, 2 non-mandatory, data types such as String, int, and character length restriction conditions. So the number of single-interface test cases designed to have, um…… If the number of input parameters and parameter types becomes too large, then the number becomes indescribable. Therefore, it is necessary to consider the tester’s mastery of interface test case design.

Interface test cases, designed for input parameters:

1. Numeric type parameters

  • Equivalence class division: within the value range, outside the value range, how to understand this?
    • If the interface documentation has a description of what values or ranges this parameter should take, use the range specified here
  • Boundary value analysis: maximum minimum just, maximum +1, minimum -1, this is to find the boundary from the value range, where the maximum and minimum are data type boundary
  • Special value design: 0 or non-positive number, possibly decimal
  • Traversal: no shortcut, exhausting its value interval, which is generally filtered out by equivalence classes and boundary values, so there is no need to exhaust;

2. String type

  • String length
    • Equivalence class: Inside or outside the range
    • Boundary value: specifies the range boundary; Type boundary
    • Special value: This needs to be distinguished from special characters of string type, which are 0 or an empty string, null
  • String content
    • Specific types: Chinese and English, upper and lower case, simplified and traditional
    • Special characters: Emoji, punctuation operation symbol, and other special characters of input method
    • Sensitive character

3. Unusual array or list types: list, for example, can be either int[]\ or string[]. His design method can not escape the above several types, I will not repeat here.

Design for business logic, design for input parameters and other aspects, especially business logic generally adopts forward use case design, a small amount of input parameter design of abnormal scenarios, the design of input parameters can almost get the expected results in input design.

Back to business!

Pycharm and IDEA are used locally as Java development tools. Pycharm and IDEA are not used locally as Python.

2. Import the local environment, since Eclipse requires an external installation of the Lombok plug-in, download the address, in addition to the installation, to see if the Java team has configured dependencies in the POM

	<groupId>org.projectlombok</groupId>

	<artifactId>lombok</artifactId>

	<optional>true</optional>
Copy the code

3. I’m a tester, and I already have jacoco installed in my environment, so I added the plugin to the Maven project.

<! -- Another plugin that does code coverage detection by the way -->

	<groupId>org.codehaus.mojo</groupId>

	<artifactId>cobertura-maven-plugin</artifactId>

      <groupId>org.jacoco</groupId>

      <artifactId>jacoco-maven-plugin</artifactId>

      <version>0.8.3</version>

    	<! -- specify the location of the generated.exec file -->

    	<destFile>target/coverage-reports/jacoco-unit.exec</destFile>

    	<! --Jacoco generates the final report from the.exec file, so you need to specify the.exec directory -->

            <dataFile>target/coverage-reports/jacoco-unit.exec</dataFile>

		<id>jacoco-initialize</id>

               <goal>prepare-agent</goal>

           <phase>package</phase>

            	<goal>report</goal>

<! - tips: jacoco command is performed in the maven: MVN clean jacoco: prepare - agent install jacoco: report - Dmaven. Test. Failure. Ignore = true -- -- >
Copy the code

4. When I used Java to assist JMeter testing, I was used to testng unit testing framework and did not do unit testing on SpringBoot framework, so I still have the following dependencies:

    <groupId>org.springframework.boot</groupId>

	<artifactId>spring-boot-starter-test</artifactId>

<! -- https://mvnrepository.com/artifact/org.testng/testng -->

	<groupId>org.testng</groupId>

	<artifactId>testng</artifactId>

	<version>6.9.10</version>
Copy the code

5. The development habit is to use junit4.x for unit testing, which will also use the spring-boot-starter-test plug-in, but the inherited class is different;

import org.junit.runner.RunWith;

import org.springframework.boot.test.context.SpringBootTest;

import org.springframework.test.context.junit4.SpringRunner;

@RunWith(SpringRunner.class)

import org.springframework.boot.test.context.SpringBootTest;

import org.springframework.test.context.testng.AbstractTestNGSpringContextTests;

public class BaseTest extends AbstractTestNGSpringContextTests {# is also used@SpringBootTestAnnotations, but it doesn't start sprintboot service, testng must inherit AbstractTestNGSpringContextTests use; #@springboottest (classes={is your SpringBoot boot app class})# For example:@SpringBootTest(classes=UserApplication.class)
Copy the code

Extension: can also be inherited AbstractTransactionalTestNGSpringContextTests class, a choice;

6. At this point, you can press Ctrl+1 on Eclipse to convert junit framework test cases into testng framework pleasant tests

Convert to TestNG(Annotations)