LN Set #5
CS3202 Set#5 QA Testing
Why Do we Test?
Reflect & list top three reasons for testing:
Topics
1. Quality Assurance 2. Reviews 3. Test Planning 4. Test Strategies 5. Test Case Design 6. Test Automation
Assurance vs Control
Quality Assurance (Process Oriented)
A set of activities designed to ensure that a process is defined and appropriate Focus is on the process elements assuring that the required level of detail is present
Testing
Executing a system with the intent of finding defects. Testing is more of a quality control activity
CS3202 Set#5 QA Testing
ANALYSIS
DESIGN
CODING
TEST
IMPLEMENT
Testing
To ensure that software meets requirements To find and eliminate software errors Testing may take 40% of development time! Have I done enough testing? Testing can only show the presence of errors testing is never complete and no amount of testing can prove program correctness
9
CS3202 Set#5 QA Testing
10
Test Automation
Version Control
Software Delivery
Continuous Integration
Low-Level Design
Coding
13
Testing Lifecycle
1. Test plan identifies:
The scope of testing effort, The methodology and tools used in testing
2. Test case design 3. Execution of test cases and evaluation of test results
code
14
Phases of testing
What and when should I test?
When to test parts of a program? When to test the entire program?
validation/system testing
module m2
unit testing
validated system
CS3202 Set#5 QA Testing
16
17
Per Functionality
Business Facing Technology Facing
Cross Functional
Usability Test Exploratory Test Property Test
Special Tools Manual
Automated
Support Development
Q1: Automated
Unit Tests Component Tests
Q4: Tools
Performance Testing Load Testing Security Testing All the -lity Tests
Q1 - Technologyfacing tests that support the team Q2 - Businessfacing tests that support the team Q3 - Businessfacing tests that critique the product Q4 - Technologyfacing tests that critique the product
Critique Product
Technology Facing
Ref: Agile Testing (Book)
20
Unit testing
The goal of unit testing is to take the smallest piece of testable software in the application, isolate it from the remainder of the code, and determine whether it behaves exactly as you expect A unit test is a piece of code that exercises another piece of code Each unit is tested separately before integrating them into modules to test the interfaces between modules. Unit testing has proven its value in that a large percentage of defects are identified during its use. You may need drivers and stubs to execute unit tests. The driver simulates a calling unit and the stub simulates a called unit. Even though the drivers and stubs cost time and money, unit testing provides some undeniable advantages. It allows for automation of the testing process, reduces difficulties of discovering errors contained in more complex pieces of the application, and test coverage is often enhanced because attention is given to each unit.
Adapted from http://www.codeproject.com/KB/architecture/onunittesting.aspx
21
Test coverage
2 4
CFG
1 3 5
One test case can cover all statements: 1, 2, 3, 4, 5 Two test cases cover all branches: 1, 2, 3, 4, 5 1, 3, 5 Four test cases cover all control paths: 1, 2, 3, 4, 5 1, 3, 5 1, 2, 3, 5
CS3202 Set#5 QA Testing
1, 3, 4, 5
23
Test coverage
We cannot cover all the paths during testing:
1 F 2 T 3 T 4 6 7 F 5
a = 3; b = 3; }
25
26
27
Functional Analysis Equivalence Partitioning Boundary Value Analysis Cause Effect Graphing Conditions Testing Loop Testing Variable Coverage Testing User Scenario Testing
28
Functional Analysis
Test the system based on external specification Based on simple concepts
What is the system expected to do How do we determine that it is doing it
29
Equivalence Partitioning
Divides the input of a program into equivalence classes of data An Equivalence Class is a set of test cases such that any member of the class is representative of any other member of the class Guidelines for Equivalence Partitioning
If an input condition
Requires a value, then at least one valid (correct format) and perhaps two invalid equivalence classes (value absent, or present but incorrect format) are defined and/or Specifies as range, then at least one valid (within range) and two invalid (above and below range) equivalence classes are defined and/or Specifies a member of a set, one valid (within set) and one invalid (outside set) equivalence classes are defined [Note: there above not exhaustive there can be other additional classes e.g.. based on black box / white box logic]
CS3202 Set#5 QA Testing
30
Decision Tables
A decision table identifies a set of actions corresponding to a set of decisions. Each column in the decision table is a testable condition. Decision tables are appropriate when
The requirements are presented in a form that can easily be mapped to decision tables. The resulting decision table are not very big Each column in the table is a unique condition independent of the other column
32
The complete set of ingoing dependencies is the cause scope of the unit, and the outgoing dependencies are the effect scope. Cause-effect graphs connect input causes to output effects
CS3202 Set#5 QA Testing
33
Conditions/Variable Coverage
Conditional Testing Aims to exercise all logical conditions in a program Execute every branch at least once Test all combinations of simple or complex conditions Test that every value in a case statement is used Test that both results of a Boolean function are generated Variable Coverage Testing Tests that every variable is accessed All global variables are used by somebody All local variables are used Variables are set or initialized properly Output parameters are set before function exit This is the most difficult and expensive form of coverage analysis, and often gives false alarms
34
Loop Testing
Simple Loops of size n Skip loop entirely Only one pass through loop Two passes through loop m passes through loop where m<n (n-1), n and (n+1) passes through the loop Nested Loops Start with inner loop. Set all other loops to minimum values Conduct simple testing on inner loop Work outwards Continue until all loop tested Concatenated Loops If independent loops, use simple loop testing if two loops are concatenated and the loop for loop 1 is used as initial value for loop2 then the loops are not independent. Use the nested loop testing approach Unstructured Loops If possible redesign into one of the above categories
35
36
37
Integration testing
Modules A and B were implemented separately
Will A and B work together ok?
Caller
Parser
Design Extractor
AST
Modifies
38
39
inputs testing
program
40
No
41
42
incomplete program
If A and B are not available, write test stubs to simulate the behavior of A and B If Caller is not available, write test driver
43
CS3202 Set#5 QA Testing
Validation/System Testing
Testing a complete system In SPA, different types of queries form system tests
Inputs: source in SIMPLE, query Output: query results
44
TA Defined (IEEE)
Use of software tools to control the execution of tests, the comparison of actual outcomes to predicted outcomes, the setting up of test preconditions, and other test control and test reporting functions. Automated testability is the degree to which the application under test facilitates the implementation, execution and maintenance of automated testing Automated testability is about interfaces: Between software under test and test software Between requirements and implemented features Between developers and testers
CS3202 Set#5 QA Testing
45
Test time Version 1.0 5000 days Version 2.0 + 1.0 * 2500 + 2500 days Version 3.0 + (2.0 + 1.0) * 2000+ 1250 + 2000 days
46
Automation of testing
Get frequent feedback Get feedback asap after code has been written
First, unit tests find problems early in the development cycle. The common wisdom in software development is that the earlier problems are found, the cheaper it is to fix them. An automated unit test suite finds problems effectively as early as possible, long before the software reaches a customer, and even before it reaches the QA team. Most of the problems in new code are already uncovered before the developer checks the code into source control. Second, an automated unit test suite watches over your code in two dimensions: time and space. It watches over your code in the time dimension because once youve written a unit test, it guarantees that the code you wrote works now and in the future. It watches over your code in space dimension because unit tests written for other features guarantee that your new code did not break them; likewise it guarantees that code written for other features does not adversely affect the code you wrote for this feature. Third, developers will be less afraid to change existing code. Over time, software systems become more and more change resistant because developers are reluctant to change old code. This is natural because when changing old code, there is always the risk of breaking it or some other part of the system through a side-effect.
48
Regression testing
Execute test cases after program modifications to see if no new errors introduced
Source program
Modify program
Update test library Autotester: Perform regression testing Library of test cases
49
Execution Reports
Hybrid Approach
50
51
52
Test Documentation
Typical Test Documentation consists of
Test Plans Test Specification/Test Case Test Logs Test Status Report Error/Problem Reports Test Case Documentation
Test case ID Test Case Description Pre-condition required for test Test Input Data Expected Result Test Procedure/ Test Script Steps to execute a test case
53
Recommendations
the developer checks in the source code - including the unit test code - to the source version control system. It is vital that the unit test code is checked in to the version control too. This allows integrating the unit tests with the build. It also allows other developers to check out the unit tests on their local machines and run them at will. before a developer checks in any code into the main source control repository, she should get the latest versions of the unit tests from the version control on her development machine and run all the tests locally. Only after all unit tests pass should the developer check in new code. This ensures that the source code in the version control system remains healthy at all times and can be used to rebuild the system at any time. to get the full benefit, test should be run as part of the build process - this is what is meant by automation of testing The build along with the tests should be scheduled to run automatically once or twice a day. If you have tests but do not run them as part of a scheduled build, then you are not getting the full benefit from the tests. By running the tests as part of a scheduled build, you test early and often.
54
55
8. Design of integration test cases: to be done before module implementation 9. Execution of integration test cases: to be done as soon as groups of interacting modules are available and re-run daily
CS3202 Set#5 QA Testing
56
57
Testing is expensive
How to reduce testing effort? Quality Assurance is not all about testing: Quality of design and code Code reviews
58
Develop & Implement Test Automation Solutions Introduce and Deploy Test Automation Solutions Review and Evaluate Software Test Automation
59
Drag Components to create tests in QC Test Engineer Configure Input/Output parameters Debug tests in QC Test Plan module Add tests to test set in Test Lab module
or
60
Strategies Guidelines
Test automation is a fulltime effort, not a sideline The test design and the test framework are totally separate entities
The test framework should be applicationindependent The test framework must be easy to expand, maintain, and perpetuate The test strategy/design vocabulary should be framework independent The test strategy/design should remove most testers from the complexities of the test framework
CS3202 Set#5 QA Testing
61
Types Of Frameworks
Test Script Modularity
requires the creation of small, independent scripts that represent modules, sections, and functions of the application-under-test
Data-Driven Testing
test input and output values are read from data files and are loaded into variables in captured or manually coded scripts
62
SUMMARY
CS3202 Set#5 QA Testing
63
Best Practices
People
Testers need to be involved early in the process Objective reviews (formal or informal) greatly complements testing Close coupling of developer and tester have significantly improved quality of software Program owners cannot be the testers themselves
Process
Risk assessment based testing yields high ROI Subset of tests that have a high probability of finding bugs are selected Incremental integration testing adds value than big-bang approaches It is important to break application under test (AUT) into smaller functional modules and map related tests. This will aid in effective regression testing Automate areas that are less prone to changes
Technology
Fully integrated test case DB, SCM and defect repository is quite useful Tool support for metric calculations are helpful
64
SUMMARY
Testing is the process of executing a program with the intent of finding errors Different types of tests are done at different phases of the Life Cycle The questions to consider before deciding on a strategy are
What is the test objective? Which technique will be best for attaining the objective? Am I comfortable in applying the technique?
Test automation requires a collaborative effort. Costeffective test automation calls for automated testability
CS3202 Set#5 QA Testing
65
Practical Testing
Some Tips & Pointers Suria R Asai (Email: suria@nus.edu.sg), ISS, NUS
Slide 1 of 15
2/12/2012
Slide 2 of 15
2/12/2012
According to wikipedia:
http://en.wikipedia.org/wiki/List_of_unit_testing_frameworks# C.2B.2B 50+ Frameworks http://www.opensourcetesting.org/unit_c.php 38 Frameworks Noel (2004): http://gamesfromwithin.com/exploring-the-c-unittesting-framework-jungle Alex Ott (2011): http://alexott.net/en/cpp/CppTestingIntro.html
SOC CS3202 SEP NUS 2/12/2012
Slide 3 of 15
http://www.objectmentor.com/omTeam/feathers_m.html http://cppunit.sourceforge.net/doc/lastest/cppunit_cookbook.html Advantage: clarity, less time to learn Disadvantage: lengthy fixtures Unit Tests Integration Samples Selective Testing (TestRunner)
SOC CS3202 SEP NUS 2/12/2012
Similar to JUnit;
Sample Demo
Slide 4 of 15
Assertions
Conditions to be checked Combine assertions; Based on some common functionality At least positive, negative and zero test case Combines several tests Logically related to each other Provides setup of data or state, needed to run test Defines cleanup of state and/or data after test is executed Types: per-test case, per-test suite, and/or global fixtures Monitors: Displays how tests are executed, and collect data about failed test TestRunner: Useful to run test macros or suites or monitors
Test cases:
Test suites:
Fixtures:
Frameworks:
For Natural Extension for CPPUnit; Whole stack for Unit, Integration and System Test Big Community Followers and Help Sample Demo
Advantages: finer control; skips tests failed and continues; easy set up & tear down; more Configurations and platform support Disadvantage: more things to learn; set up little tricky; MSVC++ has bugs and hence static dll based projects suffer[read bug reports]
SOC CS3202 SEP NUS 2/12/2012
Slide 6 of 15
Assertions
Conditions to be checked success, nonfatal failure, or fatal failure Uses an assertion Combine one or more tests; Based on some common functionality At least positive, negative and zero test case share common objects and subroutines for test cases Defines cleanup of state and/or data after test is executed
Test
Test cases:
Test Fixtures
Advanced assertions, death tests, test result formatting, parameterized tests, advanced command line test selection, repeat, shuffle and format
Comparison Chart
Characteristics Work smoothly in VS2010 External Dependency UT, IT and ST Support Assertion Macro Support Test Selectable from command line Output formatting Handling Failure Advanced Features
Slide 8 of 15
CPPUnit Yes; Simple project settings None Yes; Complete Complete Set No Text & UI Aborts current test and continues with rest of test TestRunner; Fixtures;
SOC CS3202 SEP NUS
Google C++ Testing Framework Yes; Caution regarding static DLL projects None Yes; Complete Exhaustive Set Yes; Customizable Text, UI,XML & HTML Non fatal assertions can be used to test even after failure Fixtures; Mock; Templates; Specialized data types;
2/12/2012
Slide 9 of 15
2/12/2012
Acceptance/System Test
Slide 10 of 15
2/12/2012
Test Management
Slide 11 of 15
2/12/2012
Example Tools
JIRA (Enterprise is Paid) BUGZILLA (GNU) TEAM FOUNDATION SERVER (MS) XSTUDIO (Free) QMETRY (PAID) MOCK FRAMEWORKS
Slide 12 of 15
2/12/2012
Slide 13 of 15
2/12/2012
For the project (Say XXXXProject) For White Box testing (Say XXXXProjectWBTests)
Includes unit and integration tests Test fixtures (per test case or suite) are designed Appropriate sequencing is designed for scenarios Framework options may be CPPUnit or GCTF Includes system and/or acceptance tests Use AutoTester Note: Technically all tests can be in one project, but separating WB and BB gives more clarity during regression testing
Testing Process
Keep documentation simple; Use tools to help not complicate; Minimum you need high level TC design (aka excel)
SOC CS3202 SEP NUS 2/12/2012
Slide 14 of 15
Unit Tests are independent, clear, short, unique & automated While testing complex classes use mock objects
setUp() create the describe procedure tearDown() remove it (zero residual side effects) Test for things that may be null Test for empty strings Test all but the simplest properties http://googletesting.blogspot.com/ http://code.google.com/p/googletest/wiki/FAQ
SOC CS3202 SEP NUS 2/12/2012
Slide 15 of 15
Create ample test cases and related fixtures Start connecting them into sequences using Testrunner or Google test While creating the module (first time):
Run all unit tests; upon successful completion proceed Run all integration Use bottom up or left-right integration approach Selected affected test cases and code new suites Run unit tests first followed be relevant integration suites Run the relevant system tests
2/12/2012