RSS

Tag Archives: Unit Testing

Configuring Bamboo to Show Jasmine Test Results

If you already got unit test setup that has been configured to run with karma in local environment it might be a good idea to integrate unit test suite with your continues integration(CI) server.
You can follow these steps to configure popular Bamboo build server to integrate unit test suite written with Jasmine.
1. First step on integrating with Bamboo is to generate test results file that can be understood by Bamboo server. To do that first need to go to configure build plan page in Bamboo server as shown below.

bamboo-configure-plan2. In the configuration page Locate the build job and go to job tasks configuration by clicking on the job.

job-configuration-in-bamboo

task-configuration3. Click on Add task to add a task.

4. In the add tasks configuration dialog for the selected job, we have few options to parse jasmine test results. We can add JUnit test parser, Mocha test parser etc. in this case I will show how to use Junit test parser.

task-types

5. After you add the Junit Test parser your task configuration might look similar as shown below It is super important to make sure that you add Junit test parser as a “Final Task in Bamboo”. You should ideally add them after “Final Tasks” gray bar as shown below

junit-parser-task

In JUnit parser task configuration, you should specify test reports XML path which I will describe later.

What are Final Tasks in Bamboo?

Test result parser tasks like these should always run regardless of when previous build tasks successfully ran or not. The reason is when one of unit test get failed previous build tasks might get failed but still you need to run test parser task since you need to see the failed tests too.

So in above steps we have mostly completed Bamboo configuration steps. Next we need to do is generate JUnit test result xml from jasmine tests through npm command line. This post assumes you already have Jasmine unit tests configured to run with Karma in your local environment. Covering that is beyond the scope of this post and you can find more information on that in here if you need to. If you have Karma test runner already setup you can add Karma JUnit reporter as shown below.

6. First install “karma-junit-reporter” to your unit test project with below command.

[source-code language=”java”]npm install karma-junit-reporter –save-dev[/source-code]

7. Add following to the Karma configuration. Make sure you define options for JUnit reporter as expected.

junitReporter: {
    outputDir: 'test-reports', // results will be saved as $outputDir/$browserName.xml
    outputFile: 'junit-report.xml', // if included, results will be saved as $outputDir/$browserName/$outputFile
    suite: '', // suite will become the package name attribute in xml testsuite element
    useBrowserName: true, // add browser name to report and classes names
    nameFormatter: undefined, // function (browser, result) to customize the name attribute in xml testcase element
    classNameFormatter: undefined, // function (browser, result) to customize the classname attribute in xml testcase element
    properties: {} // key value pair of properties to add to the section of the report
}

Important thing to note in this test reporter configuration is that make sure the output path you give in this step is correct as expected in above “JUnit Parser” custom result directories path as shown below.

tasks.png

8. Sample karma.conf can be as below. You might need to make sure “singlerun” to true so that test run will not hang up the build.

module.exports = function(config) {
    config.set({
        basePath: '',
        frameworks: ['jasmine'],
        files: [
            'your files here...'
        ],
        preprocessors: {},
        reporters: ['progress', 'spec', 'kjhtml', 'junit'],
        // web server port
        port: 9876,
        browsers: ['Chrome'],
        singleRun: true,
        concurrency: Infinity,
        // the default configuration
        junitReporter: {
            outputDir: 'test-reports', // results will be saved as $outputDir/$browserName.xml
            outputFile: 'junit-report.xml', // if included, results will be saved as $outputDir/$browserName/$outputFile
            suite: '', // suite will become the package name attribute in xml testsuite element
            useBrowserName: true, // add browser name to report and classes names
            nameFormatter: undefined, // function (browser, result) to customize the name attribute in xml testcase element
            classNameFormatter: undefined, // function (browser, result) to customize the classname attribute in xml testcase element
            properties: {} // key value pair of properties to add to the section of the report
        }
    })
}

8. In your build step you can run following command to run unit tests. This will generate test report
[source-code language=”java”] karma start[/source-code]
As you would understand now after the build task completes in Bamboo job, we have got the JUnit test results xml already saved to the disk. In the JUnit test parser task which runs after build task, these test results will be parsed and shown in the bamboo build results page.
In the build dashboard you will see test summary in in “Tests” tab as shown below…

build-results-1

If you need to see the test results you can click on “Job link” and see more test run details.

build results 2.png

build-results-3

If you have failing test you will see that build get failed and failed test results will be shown in build results page.

failed-build-results

If you do not see these test results when unit tests get failed, make sure you have added “JUnit Parser” as a Final task as described above in Bamboo configuration. If you have Mocha as test runner instead of Karma you do not need a converter task. Instead you can directly use Mocha test parser in Bamboo and the result of the results are much similar.

Advertisements
 
3 Comments

Posted by on February 23, 2017 in ASP.NET, Bamboo, Jasmine, NodeJs, Unit Testing

 

Tags: , , , , ,