软件测试基础-软件测试

不知道最近几年软件测试在高校中是否有专门的专业或者课程,或者说细分到测试这么细的分支。但是毫无疑问的是,软件测试已经成为软件行业一个越来越重要的分支了,因为高校里面没有专门的专业,甚至可能没有专门的课程进行系统的学习,那么从事这个行业的广大测试同行这部分的基础知识可能就都是通过自学、培训机构得来了。软件测试跟软件开发一样,也是一门系统的科学,包括的范畴也很广泛:测试流程,测试管理,测试工具,测试方法等等。

我打算利用接下来的一段时间,从wiki(维基百科,国内绝大部分用户可能无法访问)转载一些软件测试基础相关的概念,跟大家分享,首先就从软件测试的基本定义和测试用例开始。

Software testing

Software testing is the process of exercising a software to verify that it satisfies its requirements and to detect errors. Software testing is an empirical technical investigation conducted to provide stakeholders with information about the quality of the product or service under test[1] , with respect to the context in which it is intended to operate. This includes, but is not limited to, the process of executing a program or application with the intent of finding software bugs. Quality is not an absolute; it is value to some person. With that in mind, testing can never completely establish the correctness of arbitrary computer software; testing furnishes a criticism or comparison that compares the state and behaviour of the product against a specification. An important point is that software testing should be distinguished from the separate discipline of Software Quality Assurance (S.Q.A.), which encompasses all business process areas, not just testing.[citation needed]

Over its existence, computer software has continued to grow in complexity and size. Every software product has a target audience. For example, a video game software has its audience completely different from banking software. Therefore, when an organization develops or otherwise invests in a software product, it presumably must assess whether the software product will be acceptable to its end users, its target audience, its purchasers, and other stakeholders. Software testing is the process of attempting to make this assessment.

A study conducted by NIST in 2002 reports that software bugs cost the U.S. economy $59.5 billion annually. More than a third of this cost could be avoided if better software testing was performed.[2]

Scope

Software testing may be viewed as an important part of the software quality assurance (SQA) process.[citation needed] In SQA, software process specialists and auditors take a broader view on software and its development. They examine and change the software engineering process itself to reduce the amount of faults that end up in defect rate. What constitutes an acceptable defect rate depends on the nature of the software. An arcade video game designed to simulate flying an airplane would presumably have a much higher tolerance for defects than software used to control an actual airliner. Although there are close links with SQA testing departments often exist independently, and there may be no SQA areas in some companies.

The software faults occur through the following process. A programmer makes an error (mistake), which results in a defect (fault, bug) in the software source code. If this defect is executed, in certain situations the system will produce wrong results, causing a failure.[3] Not all defects will necessarily result in failures. For example, defects in dead code will never result in failures. A defect can turn into a failure when the environment is changed. Examples of these changes in environment include the software being run on a new hardware platform, alterations in source data or interacting with different software.[3]

A problem with software testing is that testing all combinations of inputs and preconditions is not feasible when testing anything other than a simple product.[4] This means that the number of defects in a software product can be very large and defects that occur infrequently are difficult to find in testing. More significantly, parafunctional dimensions of quality–for example, usability, scalability, performance, compatibility, reliability–can be highly subjective; something that constitutes sufficient value to one person may be intolerable to another.

There are many approaches to software testing. Reviews, walkthroughs or inspections are considered as static testing, whereas actually running the program with a given set of test cases in a given development stage is referred to as dynamic testing.

Software testing is used in association with verification and validation:[5]

* Verification: Have we built the software right (i.e., does it match the specification)?
* Validation: Have we built the right software (i.e., is this what the customer wants)?

Software testing can be done by software testers. Until the 1950s the term software tester was used generally, but later it was also seen as a separate profession. Regarding the periods and the different goals in software testing[6] there have been established different roles: test lead/manager, test designer, tester, test automater/automation developer, and test administrator.

[edit] History

The separation of debugging from testing was initially introduced by Glenford J. Myers in 1979.[7] Although his attention was on breakage testing, it illustrated the desire of the software engineering community to separate fundamental development activities, such as debugging, from that of verification. Dr. Dave Gelperin and Dr. William C. Hetzel classified in 1988 the phases and goals in software testing in the following stages:[8]

* Until 1956 – Debugging oriented[9]
* 1957-1978 – Demonstration oriented[10]
* 1979-1982 – Destruction oriented[11]
* 1983-1987 – Evaluation oriented[12]
* 1988-2000 – Prevention oriented[13]

[edit] Testing methods

Software testing methods are traditionally divided into black box testing and white box testing. These two approaches are used to describe the point of view that a test engineer takes when designing test cases.

Black box testing treats the software as a black-box without any understanding of internal behavior. It aims to test the functionality according to the requirements.[14] Thus, the tester inputs data and only sees the output from the test object. This level of testing usually requires thorough test cases to be provided to the tester who then can simply verify that for a given input, the output value (or behavior), is the same as the expected value specified in the test case. Black box testing methods include: equivalence partitioning, boundary value analysis, all-pairs testing, fuzz testing, model-based testing, traceability matrix etc.

White box testing, however, is when the tester has access to the internal data structures, code, and algorithms. White box testing methods include creating tests to satisfy some code coverage criteria. For example, the test designer can create tests to cause all statements in the program to be executed at least once. Other examples of white box testing are mutation testing and fault injection methods. White box testing includes all static testing.

White box testing methods can also be used to evaluate the completeness of a test suite that was created with black box testing methods. This allows the software team to examine parts of a system that are rarely tested and ensures that the most important function points have been tested.[15] Two common forms of code coverage are function coverage, which reports on functions executed and statement coverage, which reports on the number of lines executed to complete the test. They both return a coverage metric, measured as a percentage.

In recent years the term grey box testing has come into common usage. This involves having access to internal data structures and algorithms for purposes of designing the test cases, but testing at the user, or black-box level. Manipulating input data and formatting output do not qualify as grey-box because the input and output are clearly outside of the black-box we are calling the software under test. This is particularly important when conducting integration testing between two modules of code written by two different developers, where only the interfaces are exposed for test. Grey box testing may also include reverse engineering to determine, for instance, boundary values.

Special methods exist to test non-functional aspects of software. Performance testing checks to see if the software can handle large quantities of data or users. Usability testing is needed to check if the user interface is easy to use and understand. Security testing is essential for software which processes confidential data and to prevent system intrusion by hackers. To test internationalization and localization aspects of software a pseudolocalization method can be used.

[edit] Testing process

A common practice of software testing is performed by an independent group of testers after the functionality is developed before it is shipped to the customer.[16] This practice often results in the testing phase being used as project buffer to compensate for project delays, thereby compromising the time devoted to testing.[17] Another practice is to start software testing at the same moment the project starts and it is a continuous process until the project finishes.[18]

In counterpoint, some emerging software disciplines such as extreme programming and the agile software development movement, adhere to a “test-driven software development” model. In this process unit tests are written first, by the software engineers (often with pair programming in the extreme programming methodology). Of course these tests fail initially; as they are expected to. Then as code is written it passes incrementally larger portions of the test suites. The test suites are continuously updated as new failure conditions and corner cases are discovered, and they are integrated with any regression tests that are developed. Unit tests are maintained along with the rest of the software source code and generally integrated into the build process (with inherently interactive tests being relegated to a partially manual build acceptance process).

Testing can be done on the following levels:

* Unit testing tests the minimal software component, or module. Each unit (basic component) of the software is tested to verify that the detailed design for the unit has been correctly implemented. In an object-oriented environment, this is usually at the class level, and the minimal unit tests include the constructors and destructors.[19]
* Integration testing exposes defects in the interfaces and interaction between integrated components (modules). Progressively larger groups of tested software components corresponding to elements of the architectural design are integrated and tested until the software works as a system. [20]
* System testing tests a completely integrated system to verify that it meets its requirements.[21]
* System integration testing verifies that a system is integrated to any external or third party systems defined in the system requirements.[citation needed]

Before shipping the final version of software, alpha and beta testing are often done additionally:

* Alpha testing is simulated or actual operational testing by potential users/customers or an independent test team at the developers’ site. Alpha testing is often employed for off-the-shelf software as a form of internal acceptance testing, before the software goes to beta testing.[citation needed]
* Beta testing comes after alpha testing. Versions of the software, known as beta versions, are released to a limited audience outside of the programming team. The software is released to groups of people so that further testing can ensure the product has few faults or bugs. Sometimes, beta versions are made available to the open public to increase the feedback field to a maximal number of future users.[citation needed]

Finally, acceptance testing can be conducted by the end-user, customer, or client to validate whether or not to accept the product. Acceptance testing may be performed as part of the hand-off process between any two phases of development.[citation needed]

[edit] Regression testing

Main article: Regression testing

After modifying software, either for a change in functionality or to fix defects, a regression test re-runs previously passing tests on the modified software to ensure that the modifications haven’t unintentionally caused a regression of previous functionality. Regression testing can be performed at any or all of the above test levels. These regression tests are often automated.

More specific forms of regression testing are known as sanity testing, when quickly checking for bizarre behaviour, and smoke testing when testing for basic functionality.

[edit] Finding faults early

It is commonly believed that the earlier a defect is found the cheaper it is to fix it.[22] The following table shows the cost of fixing the defect depending on the stage it was found.[23] For example, if a problem in requirements is found only post-release, then it would cost 10-100 times more to fix it comparing to the cost if the same fault was already found by the requirements review.
Time Introduced Time Detected
Requirements Architecture Construction System Test Post-Release
Requirements 1 3 5-10 10 10-100
Architecture – 1 10 15 25-100
Construction – – 1 10 10-25

[edit] Measuring software testing

Usually, quality is constrained to such topics as correctness, completeness, security,[citation needed] but can also include more technical requirements as described under the ISO standard ISO 9126, such as capability, reliability, efficiency, portability, maintainability, compatibility, and usability.

There are a number of common software measures, often called “metrics”, which are used to measure the state of the software or the adequacy of the testing.

Test Case

A test case in software engineering is a set of conditions or variables under which a tester will determine if a requirement or use case upon an application is partially or fully satisfied. It may take many test cases to determine that a requirement is fully satisfied.

Test cases are often incorrectly referred to as test scripts. Test scripts are lines of code used mainly in automation tools.

Written test cases are usually collected into test suites.

Formal requirement-based test cases

In order to fully test that all the requirements of an application are met, there must be at least one test case for each requirement unless a requirement has sub-requirements. In that situation, each sub-requirement must have at least one test case. This is frequently done using a traceability matrix. Some methodologies, like RUP, recommend creating at least two test cases for each requirement. One of them should perform positive testing of requirement and other should perform negative testing. Written test cases should include a description of the functionality to be tested, and the preparation required to ensure that the test can be conducted.

What characterizes a formal, written test case is that there is a known input and an expected output, which is worked out before the test is executed. The known input should test a precondition and the expected output should test a postcondition.

Informal requirement-based test cases

For application without formal requirements, test cases can be written based on the accepted normal operation of programs of a similar class. In some schools of testing, test cases are not written at all but the activities and results are reported after the tests have been run.

Typical Test Cases format

Test Cases usually have the following components.

* Test Case Summary
* Configuration
* Initial Condition
* Steps to run the test case
* Expected behavior/outcome

Further reading

Under special circumstances, there could be a need to run the test, produce results, and then a team of experts would evaluate if the results can be considered as a pass. This happens often on new products’ performance number determination. The first test is taken as the base line for subsequent test / product release cycles.

A variation of test cases are most commonly used in acceptance testing. Acceptance testing is done by a group of end-users or clients of the system to ensure the developed system meets the requirements specified. User acceptance testing is usually differentiated by the inclusion of happy path or positive test case.

This entry was posted in 软件测试 and tagged . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *