I. Defining unit tests and integration tests 1. What is unit testing
A unit test is an automated code that invokes a method or class that is being tested, and then validates some assumptions based on the logical behavior of the method or class.
Unit tests are almost always written using the unit test framework. It is very handy to write, it is not time-consuming to run, it is fully automatic, trustworthy, readable, maintainable.
2. What is integration testing
Integration testing (integration test) means that two or more dependent software modules are tested as a group.
Cons: There is an "unexpected flaw" that, after code modification, is likely to inadvertently break existing functionality if you cannot run tests on previous features. Can be processed by "regression"
3. Differences between unit testing and integration testing
Integration tests run multiple units of code that are integrated together to confirm one or more of the results that should appear in the software;
Unit tests typically run and test only one unit in isolation
Ii. several concepts 1. What is regression
"Regression" refers to the previous good function, but now there is a problem
2. What is the system under test
Unit tests are performed on the system under Test,sut;
3. What is Legacy code
Legacy codes (Legacy code) are source code related to operating systems or other computer technologies that are no longer supported or manufactured.
There is also code called "No Test" for legacy code.
4. What is Logic code
Logic codes (logical code) refer to any small piece of code that contains logic, although it may not be very large. As long as there is one or more of the following features is the logical code: if statement, loop, switch or CASE statement, calculation, or any other type of judgment code.
5. What is refactoring
Refactoring (refractor) refers to changing a piece of code without changing its function. If you change the name of the method, you do the refactoring. If you've ever split a big method into a few small ways, you refactor the code. The code still does the same thing, but it's easier to maintain, read, debug, and change.
Three, excellent unit testing
Automatic, repeatable
Easy to achieve
Once written, you can use it in the future.
Anyone can run
Click on a button to run
Can be run very quickly
Four, test-driven development
Write unit tests, not just how to write, but also when to write in the development process, and so the introduction of test-driven development
Test-driven Development tips
1. Write a failure test to prove that the final product is missing code or functionality
2. Write the generated code to meet the expectations of the test and make the test pass
3. Refactoring Code
Reading notes-unit test Art (i)-Basics of unit testing