Wiki

Clone wiki

jummp / Quality

Quality

Jummp uses a set of Unit and Integration Tests to ensure the quality of the software. All functionality should have associated tests. Most important this is required for the service layer, but also domain classes, command objects, controllers and taglibs have to be tested. Having tests does not only ensure that the code is always working, but also provides an easy to read documentation of the API. New code should never fail an existing test. If the change requires changes to the unit tests, these should be included in the same changeset. Before a bug gets fixed, an appropriate test case should be written. Whenever new functionality is added, the tests need to be extended.

Unit Tests

Unit tests can be run from the command line through grails test-app -unit. A unit test does not require a complete spring context and is therefore faster than an integration test. Furthermore it is possible to run the unit test directly from the IDE allowing a fast verification of changed code. Unit tests cannot be used to verify code that require a running Grails application (e.g. Security). In that case an integration test is required.

Integration Tests

An integration test loads the complete Grails context and allows to do (almost) everything that is possible in a running application. Instead of the normal database an embedded database is used, which is cleared after each run test. Nevertheless the database and tables are not dropped, so ids increment. You cannot assume that the first object created in a test has the id 1.

Integration tests can be run from the command line through grails test-app -integration. It is also possible to run the integration test from inside the IDE. If you do so ensure that you execute the test in a grails context (not like a unit test) and that all include paths are set correctly (important for testing plugins).

Executing All Tests

By using grails test-app both unit and integration tests are executed. The results can be viewed in the browser through ${PATH_TO_JUMMP}/target/test-reports/html/index.html. Unfortunately the command does not include unit and integration tests from plugins. Those have to be executed in their respective folder each and generate an own report each. To circumvent this restriction an ant build file can be use, just use ant test-app. The results of each test are collected and written into the base reports folder.

Test Coverage

Jummp uses the Code Coverage plugin to generate code coverage reports. To generate these reports use grails test-app -coverage. The report can be viewed in the browser through ${PATH_TO_JUMMP}/target/test-reports/cobertura/index.html. It shows the percentage of code coverage per class and highlights the executed code. It also generates branch coverage results, though it seems to generate some false positive results. Also the generated complexity value is not useful as closures end up as new classes and "reduce" by that the complexity.

Like for executing all tests, the coverage has to be run in each plugin folder. There also exists an ant task to generate code coverage for all parts of JUMMP. Just use ant coverage. The complete report can be viewed in the browser through ${PATH_TO_JUMMP}/target/test-reports/coverage/index.html

Static Code Analysis

Jummp uses the CodeNarc plugin for static code analysis. To start the analysis use grails codenarc, the report can be viewed in a browser through ${PATH_TO_JUMMP}/CodeNarcReport.html. Explanations for the highlighted errors can be found on the CodeNarc website in the section rules. As CodeNarc is a static code analyser there is the possibility of false positives. These warnings can be suppressed by using the @SuppressWarnings annotation with the name of the rule to suppress. E.g.

class MyService {
    @SuppressWarnings('GrailsStatelessService')
    def grailsApplication
}

In opposite to the unit/integration tests CodeNarc is configured to also check the plugin directories. It is recommended to run the tests regularly as it also helps to identify strange errors caused by the missing compiler errors for missing variables, etc.

Source code complexity metrics

Jummp uses the Gmetrics plugin in order to provides calculation and reporting of size and complexity metrics of the source code.

For more information about the metrics provided, please refer to the GMetrics website.

To perform an analysis of the code and write the results to an HTML file, run: grails gmetrics

Perfomance statistics

Usage of perf4J annotations in order to analyse the performances of the code.

Updated