Measuring navigation flow JUnit test in Spring Web flow

Currently I am exploring Spring Web flow. Someone has already written a utility for measuring how well you are testing the Spring Web Flow web application navigation flow using JUnit. In this blog I am extending this utility to work with Sonar. The working project is here and Sonar plugin is here @ Github.

For people in hurry,

  • Get the latest code
  • Build the Spring Web Flow Test Sonar plugin using “mvn package”
  • Deploy sonar plugin jar located in the target folder into Sonar extension location and Start sonar
  • Run “mvn test sonar:sonar” on Spring Web Flow Coverage project
  • Finally you can go to Sonar and see the report as below

Problem Statement: Measuring Spring Web flow test coverage

In any web application there will be a page navigation flow. Frameworks like Spring Web flow, can externalize the page navigation as well as session management between each page in the navigation. In the below example, there is a simple usecase, where in we are presented with a food menu. Based on the menu presented, we can drill down further to findout more or we can cancel if we are not interested.


Based on the usecase there are overall 13 distinct navigation paths in the Spring Web Flow. We can simulate all these paths by first writing the JUnit test and use the library to keep track of all the paths tested. In our test case only 7 paths are covered, out of 13. The sonar report is as below,

Spring WebFlow flow coverage

Utility to measure the navigation flow covered in a web application

We will adopt the Test first approach, by building the JUnit test to test the flow as per this blog.  The psedocode is as below,

private XMLFlowCoveragePathListenerAdapter listener = new XMLFlowCoveragePathListenerAdapter("test-flow");

public void testStartFlow() {

//test and assert the flow

public void testNextItemInFlow() {

//test and assert the flow

public void testSecondItemInFlow() {

//test and assert the flow



This utility is in a pre-alpha state. Currently it only show information on how many navigation flows it has covered against the total number as a percentage. There are few enhancements we need to take care of. For example, we need to provide a drilldown on what are the navigation flow that is not covered. We also need to build a threshold, where if it is less than that, it should break the maven build. Ofcourse, we need to cleanup the code.

I feel even in its present form this utility is useful. Feel free to use it.

4 thoughts on “Measuring navigation flow JUnit test in Spring Web flow

  1. leoanbarasan

    Nice guide to measure the code coverage based on jUnit test case in Spring app.

    I would like to know if there are more then a jUnit classes in a Spring project. How to measure/identify the code coverage for each jUnit class? And also, as a whole how to measure?

    1. GoSmarter Post author


      Thanks for reading my blog. I am happy that you liked my blog. In general measuring Software Quality, like code quality, unit test quality, functional testing quality is a very vast subject. Over a period of time, I have build a set of favorates opensource in measuring my software in the Java world. There are corresponding tools in .Net world also. Some of the tools are,

      • Sonar: is a generic software measuring portal
      • PMD: measuring code quality
      • Cobertura, Eclemma: Measuring junit test quality
      • Fitnesse: Functional testing in a agile way
      • Selenium: UI testing
      • In the coming days, let me see, if I can write some blogs around this.


  2. Pingback: Java Web Development Frameworks: Play 2.0 and Spring MVC | Spring under the hood

  3. Pingback: JUnit testing of Spring MVC application: Testing Spring Webflow | Krishna's Blog

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s