Daml Testing Automation

How can unit testing & integration testing on Daml be automated? Any examples?

2 Likes

For unit tests, I recommend to implement them in daml script and run them in CI via daml test.

Integration tests are a bit harder to answer since they are necessarily somewhat specific to your setup as they reach outside of Daml. The common part is usually that you spin up a Sandbox instance that you use in all tests and then in each test you allocate fresh parties that you use in those tests. Depending on your app, you’ll spin up some additional components, e.g., trigger, automation written using the java bindings or something else. The tests can be written either using the Java bindings by sending gRPC ledger API commands and testing for responses, Other options are puppeteer if you’re trying to write integration tests for your web UI or writing your tests against the JSON API.
I don’t have any good example handy here.

1 Like

It’s hard to give much more guidance than "install the Daml SDK into your SDK pipeline somehow and then run daml test".

The easiest way to get the Daml SDK installed on a Linux machine is:

curl -sSL https://get.daml.com/ | sh /dev/stdin ${SDK_VERSION}

But the context in which you run that will depend on your setup. For example, if you run CI in Docker containers, you may want to add that to your Dockerfile.

1 Like

Some useful tools also mentioned in this topic:

Any application with a significant JVM client component will probably most easily be integration-tested in this Scalatest-driven way, just as we do in the daml repo. For testing just Daml code, though, this is a lot of needless complexity, which should be elided by using scripts with daml test. Testing a TypeScript application? Start and setup a sandbox first with script, and then what’s next depends on which of dozens of potential testing frameworks is in use.

All of our public repositories that host daml projects have associated CI setups in them; these may be a good starting point for any project whose testing needs are close enough to theirs.