CI/CD Running Project Tests

Now that projects are building, it is incredibly valuable to run tests against the code to validate it.

This is all the more important as in the future: in GitHub we can require that a pull request pass tests and be validated before it is merged into the main branch.

There is one tool we need for running tests and analyzing the results.

MSTest Plugin

Go to Manage Jenkins ⇾ Manage Plugins ⇾ Available Plugins and add:

Running Tests in Jenkins

Now that we have all of these components set up, we can verify we can run tests and evaluate results.

With dotnet, we can run and it will discover the solution for us:

        stage ("Run Tests") {
            steps {
                bat """
                    dotnet test --nologo -c Release --results-directory TestResults --logger trx --no-restore --no-build
                    """
            }
        }

We ought to now see a result that looks like this:

Test Results in Jenkins

We can convert test results from VSTest into a format that Jenkins expects. It takes a few extra steps, however.

We’ll add a new stage to our job to do the conversion after having run tests:

        stage ("Convert Test Output") {
            steps {
                script {
                    mstest testResultsFile:"TestResults/**/*.trx", failOnError: true, keepLongStdio: true
                }
            }
        }

While the results below don’t look as impressive…

Note: this image from an older iteration of the documentation.

If you switch to the standard view by using the right arrow in the upper right corner and navigate to the branch view, you can see:

As more builds run the graph will add more information showing progress as follows:

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.