simmac / threema-msgapi-sdk-java

Gateway MsgApi SDK - Java
https://gateway.threema.ch
Other
1 stars 3 forks source link

Code coverage in tests #4

Open simmac opened 8 years ago

simmac commented 8 years ago

From @m007 on March 27, 2015 9:0

Problem

Analyzed the code with my own SonarQube instance and found it having a test coverage of just about 55%.

How to find out

For anyone interested by running this analysis on your own: I did so by adding following lines within the <build> .... </build> tag of the pom.xml file.

             <plugin>
                <groupId>org.jacoco</groupId>
                <artifactId>jacoco-maven-plugin</artifactId>
                <version>0.7.1.201405082137</version>

                <executions>
                    <execution>
                        <id>pre-unit-test</id>
                        <goals>
                            <goal>prepare-agent</goal>
                        </goals>
                    </execution>
                    <execution>
                        <id>post-unit-test</id>
                        <phase>test</phase>
                        <goals>
                            <goal>report</goal>
                        </goals>
                    </execution>
                    <execution>
                        <id>pre-integration-test</id>
                        <phase>pre-integration-test</phase>
                        <goals>
                            <goal>prepare-agent</goal>
                        </goals>
                        <configuration>
                            <destFile>${project.build.directory}/jacoco-it.exec</destFile>
                            <propertyName>failsafe.argLine</propertyName>
                        </configuration>
                    </execution>
                    <execution>
                        <id>post-integration-test</id>
                        <phase>post-integration-test</phase>
                        <goals>
                            <goal>report</goal>
                        </goals>
                        <configuration>
                            <dataFile>${project.build.directory}/jacoco-it.exec</dataFile>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

Needless to say that you need to have a running/configured SonarQube server.

How to fix

There should be more tests. Many more tests. In 2015 nothing less than 85% is reasonable. Maybe the code should be developed test first. See TDD.

Copied from original issue: threema-ch/threema-msgapi-sdk-java#1

simmac commented 8 years ago

From @m007 on March 27, 2015 9:12

Forgot to provide a picture... So, here we go: untitled2

simmac commented 8 years ago

@m007: Do you have any ideas to improve the test coverage? A lot of classes only print results in the console (all console.commands) and another big part relies on sending and receiving messages. As ECHOECHO doesn't reply to API messages (unfortunately) we can't test message sending and receiving.

But yeah, there is still room for improvement at the Exception classes and some other classes, but the major parts can't easily be tested.