Beta Release
Assert Objectscript is a supplemental assertion library meant to enhance readability of resulting test failures.
Instead of this
AssertEquals:objectA== objectB was '6@%Library.DynamicObject'
you will get this
AssertFailure:
Expected:
%DynamicObject(value: Foo)
to be equal to:
%DynamicObject(value: Bar)
The goal of this library is to provide the developer with enough information to find the reason for a test failure without the need to debug the code.
Assert-Objectscript is available in the InterSystems Open Exchange and in the Open Exchange ZPM Registry.
To install Assert-Objectscript, open an IRIS session into your IRIS instance and run the following command in the namespace you need
zpm "install assert-objectscript"
Assert-Objectscript uses a builder pattern to construct an assertion. It consists of these steps
Each assert follows this in the fashion of assert...thatActual...isEqualTo
Since Assert-Objectscript relies on the basic ObjectScript asserts and the AssertFailureViaMacro
function, a test context with the %UnitTest.TestCase
class must be available. So you will start
any assertion like this.
set builder = ##class(utility.testing.AssertBuilder).AssertOnContext($THIS)
From there on, you have the choice between an assert on on object or array.
set arrayAssertBuilder = builder.ThatActualObject(object)
set objectAssertBuilder = builder.ThatActualArray(object)
Once constructed, you can configure your assertion. For example, you could:
UsingFieldByFieldComparison()
IgnoringOrder()
IgnoringField("ID")
Lastly, you need to finish with an assertion.
builder.ThatActualObject(actual).UsingFieldByFieldComparison().IsEqualTo(Exepcted)
All example assume that this method exists to shorten
the actual assert. You could, of course, register a macro for that, too.
Method Assert() As utility.testing.AssertBuilder
{
return ##class(utility.testing.AssertBuilder).AssertOnContext($THIS)
}
Check if an object is defined
do ..Assert().ThatActualObject(object).IsDefined()
Check if an object is not defined
do ..Assert().ThatActualObject(object).IsNotDefined()
Check if two objects are equal
set objectA = {"value": "ObjectScript Test"}
do ..Assert().ThatActualObject(objectA).IsEqualTo(objectA)
Check if two objects are equal while comparing their field values recursively
set objectA = {"value": "ObjectScript Test"}
set objectB = {"value": "ObjectScript Test"}
do ..Assert().ThatActualObject(objectA).IsEqualTo(objectB)
Check if two objects are equal while comparing their field values recursively
set objectA = {"value": "ObjectScript Test"}
set objectB = {"value": "ObjectScript Test"}
do ..Assert().ThatActualObject(objectA).UsingFieldByFieldComparison().IsEqualTo(objectB)
Check if two objects are equal while ignoring a given field
set objectA = {"value": "ObjectScript Test", "id": 1}
set objectB = {"value": "ObjectScript Test", "id": 2}
do ..Assert().ThatActualObject(objectA).UsingFieldByFieldComparison().IgnoringField("id").IsEqualTo(objectB)
Check that an array has 2 elements
set array = ["A", "B"]
do ..Assert().ThatActualArray(array).HasSize(2)
Check that an array is empty
set array = []
do ..Assert().ThatActualArray(array).ToBeEmpty()
Check that an array is not empty
set array = ["A", "B"]
do ..Assert().ThatActualArray(array).NotToBeEmpty()
Check that an array contains a value
set array = ["A", "B"]
do ..Assert().ThatActualArray(array).ToContain("A")
Check that an array does not contain a value
set array = ["A", "B"]
do ..Assert().ThatActualArray(array).NotToContain("C")
Check that two arrays are equal
set arrayA = ["A", "B"]
set arrayB = ["A", "B"]
do ..Assert().ThatActualArray(arrayA).ToEqual(arrayB)
Check that two arrays contain the same elements, regardless of order
set arrayA = ["A", "B"]
set arrayB = ["B", "A"]
do ..Assert().ThatActualArray(arrayA).IgnoringOrder().ToEqual(arrayB)
To compile, build and upload to ZPM, follow these steps:
docker-compose up -d
./open-iris-session.bat
(or ./open-iris-session.sh
on Linux)zpm
load /irisdev/app
assert-objectscript package -v
repo -n registry -r -url <registry> -user <user> -pass <pass>
(Make sure your registry url ends with a trailing /)assert-objectscript -v publish
See Contributing