Search code examples
code-coveragemybatis

myBatis code coverage tool


I am going to write code coverage tool for myBatis SQL maps.

Basically, I want to know if each statement has been called during "mvn test". The second step is to compare executed and existing statements and print difference somehow.

I wonder if it already exist because I didn't find?


Solution

  • For those who are interested in. Finally I've implemented this feature.

    Just a few facts. I've created framework based on spring-test and junit. The main goal was to test myBatis statements on multiple databases at the same time.

    Coverage tool is just a feature to help developer define missing tests. The way how coverage tool is working could be explained as following steps:

    • get all statement names from myBatis once using getMappedStatementNames() method from SqlMapExecutorDelegate class.
    • collect all statement names that was called.
    • print difference between all and executed to the log.

    There are many other improvements to this small test framework. And then all this stuff integrated into automated build system, integrated with Bamboo server etc.

    At the end I've got output like this:

    WARN  18/04/2012 15:14:50 (MultipleDatabaseRunner.java:108) COVERAGE: Statement Audit.getAudit wasn't tested.
    ...