• +43 660 1453541
  • contact@germaniumhq.com

Integrating Behave Test Results in Jenkins


Integrating Behave Test Results in Jenkins

Behave it’s a fantastic BDD testing framework. In case you have no idea what BDD is, it’s a way of writing your tests in a human readable fashion (i.e. English), and implement each sentence in code.

While behave nicely outputs the executed scenarios from the feature files, you might want to see them as part of the Jenkins build reports. After all there’s a reason why we have them integrated in our CI system, for us to get a faster overview on what go wrong instead of digging through megabytes of logs.

In order to do that only 2 very simple steps are necessary:

1. Tell behave to output junit reports

Jenkins can consume junit reports. The junit xml reporting format is so popular that most testing tools can output it.

In order to do that in the case of behave, it’s simply adding --junit, so your stage would be something similar to this:

stage('Tests') {
    node {
        deleteDir()
        checkout scm

        sh """
            behave --junit
        """
    }
}

Only the --junit flag was added, all the other flags, such as selecting what tags will run, are still possible of course.

2. Import the reports into Jenkins

After that’s done, we need to get the reports from the node, into Jenkins:

stage('Tests') {
    node {
        deleteDir()
        checkout scm

        try {
            sh """
                behave --junit
            """
        } finally {
            junit 'reports/*.xml'  (1)
        }
    }
}

The junit pipeline command will do the integration of the test result in Jenkins.

Yes, it’s that easy.

After that this is what you’ll see in your Jenkins UI in the build overview:

Jekins Build Overview

When you’ll click on that Test Result link, you can see the feature files, and each scenario is marked as a test.

Jekins Scenario Overview

The results are also visible in Blue Ocean:

Jekins Blueocean Overview

Happy testing!