align:right

sasjs test

https://slides.sasjs.io/test

align:right

Why use SASjs?

  • Open Source (MIT) & Actively Developed
  • Work locally with your preferred tools
  • Faster iterations / time to value
align:right

Why Write Tests?

  • Reduce Manual Testing
  • Avoid Regression
  • Documentation
align:right

Why use SASjs for Tests?

  • Run each test in isolated session
  • Easily rerun tests in debug mode
  • Test Setup / Teardown routines
  • Integration with sasjs doc
  • Test Coverage reports
align:right

What is SASjs?

  1. An Opinionated Approach for SAS Solution Delivery
  2. A Collection of Tools
align:right

What is a SASjs Test?

A SAS program that performs one or more assertions

Filename pattern: [filename].test<.integer>.sas

some_service.test.sas
some_job.test.0.sas
some_job.test.1.sas

The test integer is optional. If provided, tests execute accordingly - eg some_job.test.0.sas before some_job.test.1.sas.

align:right

Creating Tests

align:right

Test Body

An example of a test that provides a result:

data work.test_results;
  test_description="some description";
  test_result="PASS";
  test_comments="We did this & that happened";
  output;
run;
%webout(OPEN)
%webout(OBJ, test_results)
%webout(CLOSE)
align:right

Assertion Macros

A number of ready made assertion macros are available in the SASjs Core library:

align:right

Examples of SASjs Tests

align:right

Test Coverage

A SAS Service, Job or Macro is covered if there is a test with the same filename, eg:

├── some_service.sas
├── some_service.test.sas
├── some_job.sas
└── some_macro.test.0.sas

In this example, some_service.sas is covered, some_job.sas is not covered, and some_macro.test.0.sas is a standalone test.

Coverage is file level. We have plans for line level - just need a sponsor!

align:right

Deploying Tests

align:right

SASjs Developer Workflow

align:right

CLI Pre-Requisites

Required Recommended Recommended
vertical border-style:solid vertical vertical

To install the CLI: npm i -g @sasjs/cli

align:right

SASjs Primary Artefacts

Type I/O Returns
Job Data Inputs / Outputs Success / Error
Service Web Inputs / Outputs JSON / Other Content Types
Test N/A Pass / Fail Object

Services & Tests are compiled with %webout() macros, for generating JSON in SASjs format. See also: https://cli.sasjs.io/artefacts/

align:right

SASjs Secondary Artefacts

These items are bundled into each Primary Artefact when listed in the program header

  • SAS Macros
  • SAS Includes
  • Binary Files
  • initProgram
  • termProgram
align:right

SASjs Config File

Every SASjs Project has a sasjs/sasjsconfig.json file, for configuration of:

  • Location of Artefacts (+ Dependencies & Init/Term programs)
  • Macro Variables
  • Target attributes / connection settings
align:right

🎯 SASjs Target 🎯

A location on a SAS server

Core attributes:

  • name > Alias for SASjs commands, eg: sasjs deploy -t dev3
  • serverUrl > Protocol + Host + Port
  • serverType > either SASVIYA, SAS9 or SASJS
  • appLoc > Root deployment folder in SAS Drive or Metadata
align:right

sasjs cbd Syntax

  • sasjs compile: Self-contained Jobs, Services, Tests
  • sasjs build: Deployment pack (JSON / SAS Program)
  • sasjs deploy: Send to target

Compile/Build/Deploy project to myTarget: sasjs cbd -t mytarget

align:right

Running Tests

align:right

sasjs test Syntax

Execute all tests (default target): sasjs test

Execute tests in "macros" folder: sasjs test /macros/

Prevent pipeline fail: sasjs test --ignoreFail

Execute all tests starting with "mv_" and save the output in 'myresults' folder

sasjs test mv_ --outDirectory /somedir/myresults

align:right

Resources

* MIT licence, no restrictions. Any version of SAS * Single command to deploy to a server, one more to run the tests. Share config between developers. * VS Code has a plugin but the CLI can also do everything.

optionated - working locally, git centric, server agnostic