Professional Documents
Culture Documents
Best Practices in Unit Testing Automation PDF
Best Practices in Unit Testing Automation PDF
Once the source code has been generated it must be tested to uncover (and correct) as many errors as possible before
delivery. In order to achieve this, testing must be conducted systematically & test cases must be designed using
disciplined techniques so that they have a high likelihood of finding errors. Unit testing is one such testing technique
which reveals errors in our application at early stage of software development process.
Unit testing is a process of verification and validation of individual units of source code in isolation. The key idea is that
each piece of code needs its own tests and the best person to test that code is the developer working on it. Hence, unit
testing is typically performed by developers in a development cycle, rather than in the QA phase. By performing unit test,
programmers can catch bugs early before they cause significant problems or delays in the later phases. However, manual
process of writing test cases, running tests, monitoring the test results, and pinpointing further areas for testing consumes
more time and effort. Hence automation is essential.
First step towards the automation is usage of unit testing frameworks. They can be considered as intermediate between
manual testing techniques and automated unit testing tools. These frame-works provide an interface to write and execute
manually written tests. They define how to structure your test cases and provide the tools to run them. Though, effort
and time required here is also higher, testing with frameworks ensures more coverage, reusability and repeatability of
tests. Further, these tests can be easily managed and maintained throughout the product life cycle.
WiproUT is an automated java unit testing tool developed and owned by Tools Group, Wipro Technologies. It
automatically generates and executes Junit, Cactus test cases by taking compiled source code as an input.
Strategy:
Effective testing is important, so is the strategy. By reviewing the Test Specification prior to testing, one can assess the
completeness of tests and testing tasks. An effective test plan and procedure will lead to the orderly construction of the
software and the discovery of errors at each stage in the construction phase.
Test cases should be designed to ensure that individual units of program are structurally correct and function as expected.
These tests should adequately exercise functionality of all internal components, program logic and loop conditions. Such
test cases later become the foundation for Regression testing practice (regular, repeatable verification of the code base).
Unit test design typically involves writing test harnesses, specifying input data and supplying stubs/mock objects for
missing functions.
Unit testing automation tools provide us unit testing capabilities in simplified manner. They come with the capability to
generate test cases in a high level at the click of a button, by using code as input. To test the complex logic implemented
code, tool generated tests can be customized to test all paths, conditions and logic.
Knowing the internal working & specified function that a product has been designed to perform, tests can be executed to
demonstrate each function is fully operational while at the same time searching for errors in each function. Post test
execution closure of defects has to be done with highest priority,
Tools provide an effective interface to run all tool generated/customized test cases with centralized testing, debugging
and reporting environment. On executing tool generated/user defined/legacy tests it reports problems like functionality
related issues, regression related issues, unexpected runtime exceptions organized by error categories and severities.
Recommended steps to execute test cases and close defects using tool:
Coverage analysis:
Code coverage analysis measures the degree to which the source code has been tested. It is the way to verify
effectiveness of source code as well as test cases. In other words, the coverage of code is the best indication of how well
the code has been tested. Coverage analysis results can also be used to identify unexecuted code of program (dead code).
Most of the unit testing tools offer both customizable annotated representation of covered/ uncovered code and sharable
coverage statistics. Coverage analyzer can be executed post test case execution to get the coverage details in which
coverage at different levels including line coverage and decision coverage can be tracked.
Features of tools
Technol
Tools Project specific Automatic Test Test Data Coverage Build Integratio
ogy Reports
configuration Generation Execution Sourcing Analysis integration n with IDE
WiproUT
Java
JTest
*Junit,
*Cactus x x x x
C++Test x
C/C++
*CppUnit x x x x
.Test x
.Net
*NUnit x x x x
* Frameworks
Conclusion:
All of us are interested in improving the quality of the applications we develop. However, formal manual testing
methodologies are simply impractical to implement for 100% of code coverage. Tool-assisted process offers both an
efficient and effective ways to identify and locate defects –without requiring painstaking tasks.
Further, the best tools alone aren’t enough; well-defined processes aren’t enough. What’s required is,
A lifecycle approach to quality,
Structured planning and design of the environment,
Consistent use of best practices.