Test, Inspection and Metrics
Test Types
You might have come across this quote: A code that cannot be tested is flawed.
As an important CI practice, you need to execute
:
- Unit test (using tools like JUnit, NUnit, PHPUnit, as appropriate).
Test Types
- Integration or Component test: To verify how certain changes interact with the rest of the system (using tools like JUnit, NUnit, DBUnit).
- System test: To completely test a software (using tools like JWebunit).
- Functional test: To test the software functionality from a user perspective (tools like Selenium are used).
Automate the tests using the tools provided.
Testing Strategy
- Categorize your tests (unit, system, component).
- Create test scripts and include them as part of the build.
- Ensure proper test code coverage.
- Schedule the build based on the test category. Different intervals need to be planned for slow-running tests.
- Prioritize and run faster tests.
Inspection Activities
Code review plays a crucial role in maintaining the overall quality of a codebase. This must be part of the build.
- Leverage automated inspectors like JavaNCSS or CCMetrics to identify the piece of the code that is highly complex.
The complexity of the code is determined by Cyclomatic Complexity Number (CCN).
It is the measure of:
- Number of linearly independent paths (or)
- Number of ways present to traverse a piece of code.
It determines the minimum number of test inputs required to check all the ways of executing a program (done using a control flow graph).
Inspection Activities Contd.
- Report coding standards violation (using PMD, FxCop, and so on).
- Identify the amount of duplicate code (using tools like Simian, CPD).
- Assess code coverage, identify the percentage of code executed on running a test (using tools like NCover, Cobertura, Clover).
- Determine if a package is highly dependent on other packages, measured using
Afferent and Efferent coupling
.
Afferent and Efferent Coupling
Coupling is a measure of dependencies.
Afferent Coupling
- Who depends on you
- Measure of how many other packages use a specific package.
- Incoming dependencies
Efferent Coupling
- Who do you depend on
- Measure of how many different packages are used by a specific package
- Outgoing dependencies
Build Metrics
Build metrics
plays a crucial role in helping reduce the build duration.
The following are some important build metrics:
Compilation time
: Time taken to compile the software, compares with the past compile times.Number of Source Lines of Code (SLOC)
: System’s size or size of what has to be compiled.Number and types of inspections
: Number of different inspections performed.
Build Metrics Contd.
Build Repair Rate
: Time taken to repair a build failure.Test execution time
: Time taken to perform testing at each level like unit, component, and system.Inspection time
: Time taken to perform the inspections.Deployment time
: Time taken to deploy the software.Database rebuild time
: Time taken to rebuild the database.
Analyze Metrics
Capture and analyze the metrics to determine
what improvement
must be done to reduce the build duration.
The following are such improvement outcomes:
- Improve test performance
- Streamline integration builds
- Improve inspection performance
- Distribute integration builds
Broken Build
If any activity that is performed as part of the build fails, then build is considered broken
.
-
Do not commit changes of a broken build to the work branch or mainline.
-
Fix broken builds immediately.
-
Do not check out changes related to a broken build.
Summary
You have learnt about:
- Build
- Activities that are part of a build
- Build types and mechanisms
- Build practices like run fast builds and so on
- Tests
- Metrics