In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-21 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
Most people do not understand the knowledge points of this article "how to achieve SpringBoot+TestNG unit test", so the editor summarizes the following contents, detailed content, clear steps, and has a certain reference value. I hope you can get something after reading this article. Let's take a look at this "how to achieve SpringBoot+TestNG unit test" article.
Background
Due to the tight schedule of development tasks and incomplete provision of interfaces and basic data, coverage testing cannot be carried out comprehensively and effectively even if a comprehensive interface test case is designed. And because the direction of single-interface test case design is input and output parameters, starting from the input parameters is the parameter required check, parameter type and parameter boundary value, and then there is a combination of input parameters, such as an interface 5 parameters, 3 required, 2 non-required, data types have string, int, etc., as well as character length restrictions, so the number of such single-interface test cases is designed to have, uh-huh. Innumerable, if the number of input parameters and parameter types become more, then this number is indescribable, so it is necessary to consider the tester's mastery of the interface test case design method.
The API test case is designed for the input parameters:
1. Parameters of numeric type
Equivalence class division: within the value range, outside the value range, how to understand this?
If the interface document describes which values or intervals should be taken for this parameter, it is within and outside the range specified here.
Boundary value analysis: maximum and minimum just right, maximum + 1, minimum-1, this is to find the boundary from the value range, in which the maximum and minimum is the data type boundary.
Special value design: 0 or non-positive number, possible design decimal
Traversal: there are no shortcuts, and its value range is exhausted, which is generally filtered out by equivalence classes and boundary values, not exhaustive.
2. String type
String length
Equivalence class: inside and outside the value range
Boundary value: specified range boundary; type boundary
Special value: this needs to be distinguished from special characters of string type, which refers to 0 or empty string, null
String content
Specific types: Chinese and English, upper and lower case, simplified and traditional
Special characters: emoji emoji, punctuation operation symbols, other special characters of input method
3. Rare array or linked list types: for example, the list type may be int [] or string [], and his design methods can not escape the above, so I won't repeat them here.
Design for business logic, design for output parameters and so on, especially business logic generally adopts positive use case design, a small number of exception scenarios are designed through input parameters, and almost all the design of output parameters can get the desired results.
Let's get back to the point!
1. Use eclipse as a java development tool locally, and support programming in python environment, so you don't want to use Pycharm and IDEA at the same time.
Org.springframework.boot spring-boot-starter-parent 2.4.0 org.springframework.boot spring-boot-starter-web 2.4.0
Tips:@SpringBootApplication@RestController@RequestMapping, etc. Notes
2. To import the local development environment, eclipse needs to install the lombok plug-in externally. The eclipse configuration file eclipse.ini adds the lowest parameter:-javaagent:lombok.jar, with the download address, in addition to the installation, and whether the java team has configured the dependency in pom.
Org.projectlombok lombok 1.18.12 true
3. I am a tester, and the jacoco plug-in has been installed in the original environment, so the plug-in has also been added to the maven project:
Org.codehaus.mojo cobertura-maven-plugin 2.7 org.jacoco jacoco-maven-plugin 0.8.3 target/coverage-reports/jacoco-unit.exec target/coverage-reports/jacoco-unit.exec jacoco-initialize prepare-agent jacoco-site Package report
4. When I used java to assist jmeter testing, I was accustomed to the testng unit test framework, and I haven't done unit testing on the springboot framework yet, so the following dependencies need to be added to the pom file:
Org.springframework.boot spring-boot-starter-test test org.testng testng 6.9.10
5. Developers are accustomed to using junit4.x for unit testing, in which the plug-in spring-boot-starter-test is also used, but the inherited classes are different.
# junit4.x is used as follows: import org.junit.runner.RunWith;import org.springframework.boot.test.context.SpringBootTest;import org.springframework.test.context.junit4.SpringRunner;@SpringBootTest@RunWith (SpringRunner.class) public class BaseTest {} # and replaced with testng is used as follows: import org.springframework.boot.test.context.SpringBootTest;import org.springframework.test.context.testng.AbstractTestNGSpringContextTests @ SpringBootTestpublic class BaseTest extends AbstractTestNGSpringContextTests {} # also uses the @ SpringBootTest annotation, but it is different to start the sprintboot service. Testng must inherit the AbstractTestNGSpringContextTests use # extension: you can also inherit the AbstractTransactionalTestNGSpringContextTests class, choose one of the two; # @ SpringBootTest (classes= {is your SpringBoot startup app class}), for example: @ SpringBootTest (classes=UserApplication.class)
6. At this point, you can press Ctrl+1 on eclipse to transform the test case of the junit framework into a pleasant test of the testng framework: Convert to TestNG (Annotations)
7. Extension: add swagger dependencies to generate interface documents; lombok relies on getter and setter methods that support declaration fields, and there are also tools such as integrated Log logs.
For the rest, don't read my article, it depends on your own performance. The unit test case is as follows:
Package com.text;import xxx.xxx.xxxpublic TestSampler extends BaseTest {@ BeforeClass void bf () {/ / test the preconditions for writing the test, those data that need to be executed only once} @ Test void test_add () {/ / write the code to be tested here} / /. } the above is about the content of this article on "how to implement SpringBoot+TestNG unit testing". I believe we all have some understanding. I hope the content shared by the editor will be helpful to you. If you want to know more about the relevant knowledge, please follow the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 211
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.