UnitTestSCAD: Unit Testing for OpenSCAD
!License  !coverage 
!UnitTestSCAD: expect(cube.scad).toBe(cube);
UnitTestSCAD brings forth unit testing capabilities to OpenSCAD. Unit testing enables you to check for regressions, accuracy and robustness of code in a fast, repeatable manner. Speed of development increases as unit tests will worry about your regressions, and allow you to plow ahead with your vision.
Simply start by installing OpenSCAD if you have not done so already:
While the path will generally be the same on all platforms (Windows, Linux, Mac), the file they point to specifically is different. If you have moved the respective file manually, you will need to point at:
- Windows: openscad.com
- Linux: openscad.exe
- Mac: openscad.exe
These files will be in the location where you installed OpenSCAD. For example, by default on Windows: C:/Program Files/OpenSCAD.
Note: The path to the folder containing the files is to be added to the PATH environment variable.
To install UnitTestSCAD, run the command:
npm i unittestscad
``javascript`
const UnitTestSCAD = require('unittestscad');
UnitTestSCAD exposes several classes designed to enable assertions on your .scad functions and modules. For example, to assert against a .scad file which produces a 3d model (my3dmodel.scad), you can create it as such:
`javascript
const my3dmodel = new UnitTestSCAD.ThreeDModule({
include: ['my3dmodel.scad'],
variables: {
points: '[[0, 0], [1,1]]',
range: '[0 : 20 : 80]',
width: 5.56,
text: '"some text"',
withExtension: true,
$fn: 100,
}
});
expect(my3dmodel.width).toBe(5.56);
``