BookmarkSubscribeRSS Feed

Automate SAS 9 Code Unit Tests in a DevOps Pipeline with Jenkins and SASUnit Part 1

Started ‎09-03-2020 by
Modified ‎09-06-2020 by
Views 3,912

To be truly CI/CD, you need to design and perform automated tests. Test automation reduces dramatically the time to release a feature by detecting errors early. Learn how to set up a simple DevOps pipeline in Jenkins, integrate a unit testing framework,  SASUnit, and visualize the results.

 

Code development in continuous integration was introduced in the previous posts:

Time to focus on testing and more specifically, test automation. The topic can be very broad and we will break it into several parts:

  1. Setup SASUnit, a SAS 9 Testing Framework -> next post
  2. Setup Jenkins to work with SASUnit
  3. Add a new unit (SAS code) and test in SAS Unit
  4. Visualize tests results ⭢ this post
  5. Towards Continuous Testing

This post presents the test results. In a test automation process, this is one of the last steps. It is maybe worthy you know what the end result is, before moving to more details.

Summary

To replicate the examples, you need the following technical components used: SAS 9, SAS 9 machine (Windows), Jenkins, Jenkins agent, SASUnit, Jenkins plugins: SASUnit, Blue Ocean, GitLab.

 

1400-SAS9-Test-Automation-Diagram-e1597997127238-1024x628.png

Select any image to see a larger version.
Mobile users: To view the images, select the "Full" version at the bottom of the page.

 

SASUnit is a testing framework developed by a SAS partner. The code is open sourced on SourceForge and subject to a GNU General Public License. SASUnit integrates well with Jenkins through a plug-in.

 

There are nice features that accelerate testing and centralize testing results. SASUnit is not a SAS supported product and you should treat like any open source project.

Jenkins unit test pipeline

A Jenkins pipeline launches the unit testing in a build. I find Blue Ocean, a Jenkins plugin, quite useful to visualize the build and test results.

Step 1 Jenkins starts the build on the SAS 9 machine

Jenkins connects to the agent, the Windows machine on which SAS 9 is running. The SASUnit installation folder is checked. SASUnit is the testing framework launching the tests.

 

1410-SAS9-Test-Automation-Jenkins-pipeline-build-1.png

Step 2 Jenkins launches the unit tests through SASUnit

Jenkins launches the unit tests in SASUnit, through the SASUnit Jenkins plugin.

 

1410-SAS9-Test-Automation-Jenkins-pipeline-build-2.png

Step 3 Jenkins archives the artifacts and publishes the reports

After the tests ran successfully, the post-build steps will archive the artifacts. Tests will be evaluated and test results published as test reports.

 

1410-SAS9-Test-Automation-Jenkins-pipeline-build-3.png

 

A threshold qualifies the build as unstable. The threshold was defined in the 'Publish JUnit test result report'.  You will see how you can use the attribute to chain pipelines, create dependencies and use the stable / unstable attributes as triggers in a future post.

Test artifacts

Artifacts are various by-products generated during the process of software testing.

 

In the pipeline post build steps, the artifacts have been “grabbed” from the Jenkins pipeline workspace. As a reminder, the workspace is a folder on the Jenkins agent, the machine where SAS 9 is running.

 

1420-SAS9-Test-Automation-Jenkins-pipeline-Artifacts.png

 

Artifacts are generated at each build. They are archived, in case you need to look at them later, or compare different build versions. The artifacts are generated by SASUnit, when the unit tests are complete.

Test results

After the unit testing is complete you can consult the results. 55 test cases were executed, 3 failed and 52 have passed. A short description is available for the failed tests only. Unit tests have to be designed fast, not to slow the development pipeline.

 

Unit testing resembles more drag racing, than the 24 Hours of Le Mans.

 

1430-SAS9-Test-Automation-Jenkins-pipeline-Tests.png

 

The test results in the screen are fed from a junit.xml file (generated by SASUnit). The JUNIT.xml format is a standard way to report the test suite execution results. These XML files can be processed by programs like Jenkins to display results of the tests.

 

It is interesting to look at the structure of such a junit.xml file. You can open it from the Artifacts tab.

 

1440-SAS9-Test-Automation-SASUnit-junit_xml.png

Classic View

In Jenkins you can switch from Blue Ocean to the Classic view. A summary is then condensed on a single page.

 

1450-SAS9-Test-Automation-Jenkins-pipeline-classic-tests-overview-1024x457.png

 

In the Test Result, the tests, failed and successful are displayed.

 

1460-SAS9-Test-Automation-Jenkins-pipeline-classic-tests-results.png

 

In History, you can see the evolution in time of the number of failed tests, total tests executed and their execution time.

 

1460-SAS9-Test-Automation-Jenkins-pipeline-classic-tests-results-history.png

SASUnit HTML Report

The testing framework may generate several reports and test documentation. SASUnit is generating a HTML report and test documentation, now saved in the Jenkins pipeline workspace.

 

1470-SAS9-Test-Automation-Jenkins-pipeline-classic-tests-HTMLreport.png

 

The SASUnit report landing page:

 

1480-SAS9-Test-Automation-Jenkins-SASUnit-main-e1597712730253-1024x613.png

 

The tests can be organized in SASUnit in a hierarchy: Test Scenarios ⭢ Test Cases ⭢ Assertions.

 

A test scenario is a group of test cases.

 

1490-SAS9-Test-Automation-Jenkins-SASUnit-test-scenarios-1024x622.png

 

The scenario is successful if all the test cases pass.

 

1500-SAS9-Test-Automation-Jenkins-SASUnit-test-cases.png

 

A test case relates to a unit under test. The unit under test is the developed code. In DevOps world, you should think of unit as a single feature. The 1500 lines of code your colleague wrote and everyone loathes to maintain, contains many features.

 

1510-SAS9-Test-Automation-Jenkins-SASUnit-test-case-details.png

 

A test case can have several assertions. An assertion is a Boolean expression at a specific point in a program which will be true unless there is a bug in the program. A test assertion is defined as an expression, which encapsulates some testable logic specified about the unit under test.

 

1520-SAS9-Test-Automation-Jenkins-SASUnit-assertions.png

Conclusions

A test automation setup with SAS 9, SASUnit, a testing framework and Jenkins, an automation server can speed up testing, shorten development lifecycle and organize the test results in a logical, meaningful and transparent manner.

Next

Navigate through the post series:

  1. Visualize tests results ⭢ this post
  2. Setup SASUnit, a SAS 9 Testing Framework ⭢ next post
  3. Setup Jenkins to work with SASUnit
  4. Add a new unit (SAS code) and test in SAS Unit
  5. Towards Continuous Testing

Recommended Resources

Thank you for your time reading this post. Please comment and share your experience with SAS and DevOps.

Version history
Last update:
‎09-06-2020 10:21 PM
Updated by:
Contributors

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

Free course: Data Literacy Essentials

Data Literacy is for all, even absolute beginners. Jump on board with this free e-learning  and boost your career prospects.

Get Started