Unit Test JUnit

Source: Internet
Author: User

1. Software Development process: Project research, requirement analysis, software design, program coding, software testing, operation and maintenance.

2. Software Testing Definition: The use of test tools according to test scenarios and processes to perform functional and performance testing of the product, the use of manual or automated means to run a system, the purpose is to check whether to meet the required requirements, to confirm the difference between the expected results and the actual results.

3. Software Testing

Black box testing focuses on testing the performance requirements of the software, the tester does not consider the internal structure and characteristics of the program, only need to know the program input or output between the relationship or program functions.

White box testing focuses on the structure inside the program. It is necessary for testers to be very clear about the internal structure of the program being tested, starting with the internal logical structure of the program to determine whether the actual situation is consistent with the expected state.

Regression testing when the program code is modified, re-test to confirm that the modification did not raise an error or cause other code to produce an error.

The minimum level of testing in the development of unit test software is also the minimum granularity test. A feature or block of code in the main test program. The work of unit testing is generally undertaken by programmers.

4. Unit Testing

Overview:

Unit testing is the lowest level of test activity to be performed during the software development process, where the independent unit of the software is tested in isolation from other parts of the program. Unit testing is not only used as an adjunct to error-free coding in the one-time development process, unit testing must be repeatable, whether in software modifications, or in the process of porting to a new operating environment. Therefore, all tests must be maintained throughout the lifecycle of the software system.

Why Use unit tests:

When we write code, we are sure to repeatedly debug it to make sure it compiles. If the code is compiled without passing, no one is willing to hand it over to their boss. But the code is compiled, it just shows that its syntax is correct, we can not guarantee that its semantics are certainly correct, no one can easily promise that this code behavior must be correct. Fortunately, unit testing is a guarantee of our commitment. Writing unit tests is used to verify that the behavior of this code is consistent with what we expect. With unit testing, we can confidently deliver our own code without any worries.

Unit testing as early as possible, early to what procedure? In the actual work, you can not emphasize the first what after what, it is important to be efficient and feel comfortable. From experience, first write the framework of the product function, then write the test function, write the test case for the function of product function, then write the code of the product function, run the test every function point, and add the test case at any time. The so-called first product function of the framework, is to write a function empty implementation, there is a return value of the random return a value, compiled through the test code, which is, the function name, parameter table, return type can be determined, the written test code will need to modify the possibility of less.

Unit testing is different from other tests, unit testing can be seen as part of the coding work, should be done by the programmer, that is, the code after the unit test is the completed code, the submission of the product code to submit the test code at the same time, the test department can do a certain program audit.

Unit testing is not only used as an auxiliary means of error-free coding in a one-time development process. Unit tests must be reusable. Whether it's in software modification or porting to a new running environment. Therefore, all tests must be maintained throughout the lifecycle of the software system.

Advantages of Unit Testing:

(1) It is a validation behavior

Each function in the program is tested to verify its correctness. It provides support for future development, even in the late stages of development, and we can easily add functionality or change the structure of the program without worrying about breaking important things in the process. And it provides a guarantee for refactoring code so that we can improve the program more freely.

(2) It is a design behavior

Writing unit tests will allow us to observe, think, and especially write Tests from the caller, forcing us to design the program into easy to call and testable, forcing us to release the coupling in the software.

(3) It is an act of writing a document

Unit testing is a priceless document, which is the best document to show how a function or class is used. This document is compiled, can be run, and it remains up-to-date, always in sync with your code.

(4) It has a regressive

Automated unit testing avoids code regressions and can run tests quickly and anywhere, once written.

Scope of unit Testing:

It may seem difficult to define a clear scope for unit tests and to point out which features are part of unit testing, but the four issues discussed below are the work that unit tests need to do.

1. Does it behave the same as I expected?

This is the fundamental purpose of unit testing, and we are using unit tests to verify that what it does is what we expect.

2. Has its behavior been consistent with what I expected?

Writing unit tests, if you only test the correct path of the code, let it go through correctly, not really done. Software development is a very complex project. When testing whether a piece of code is consistent with your expectations, you need to make sure that, in any case, the code is consistent with your expectations: for example, the parameters are suspicious, the hard disk has no space left, the buffer overflows, and the network is dropped.

3. Does the unit test explain my intentions?

Unit tests can help us understand the use of code, and in effect, unit tests are like documents that can be executed. Describes the functions you call code with various conditions that you expect this piece of code to accomplish.

4. Can we rely on unit testing?

Code that cannot be relied upon is of little use. Since unit testing is used to ensure the correctness of the code, Unit testing must also be worth relying on.

The process of unit testing:

In general, we divide the process of unit testing into planning, design, execution, review, and several other steps.

(1) Plan: The unit Test plan needs to clear the test target, including the test object, the test requirement, the test tool and so on.

(2) Design: The unit eats the design mainly completes the plan and the model confirmation.

(3) Perform: test the unit against the Unit test plan and use case, validate the results of the test, and record the errors that occurred during the test.

(4) Review: Evaluate the results of unit tests and generate unit test reports.

Function Point test: The main test module is the correct implementation of the specified function, there is no missing function. Here is the concept of a feature overlay. Because the module being tested may include multiple function points, the test cases that are designed to cover these function points are covered when testing, so that the functional points are tested and the general requirements feature coverage is 100%.

Coverage testing: In the case of unit tests that typically require statistical statement coverage and branch coverage, while requiring all critical paths to be tested, it is important to point out that in exceptional cases the statement and branch coverage are difficult to reach 100%, so you need to give reasons for statements and branches that are not running.

Module interface test: Refers to the test module through the data flow test, including the module interface, including parameter list, call submodule parameters, full data, file input and output operations must be checked.

The content of internal data flow is mainly the design test case Check data type description, initialization, default value and other aspects of the problem, but also to query the whole process of the impact of data on the module.




This article from "10281302" blog, declined reprint!

Unit Test JUnit

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.