Testing#

Testing for BridgeStan is primarily done through the higher-level interfaces.

All tests are based around the same set of test models (in the test_models/ folder).

You can build all of the test models at once with

make STAN_THREADS=true test_models -j<jobs>

Note: The additional functionality provided by STAN_THREADS is only required by the Julia and Rust tests, but in order to facilitate the same built models being used in all tests we use it regardless of interface.

Tests for the compilation utilities in the various interfaces also rely on being able to find the BridgeStan source. This is best done with the environment variable BRIDGESTAN. On Linux and macOS, this can be set with export BRIDGESTAN=\`pwd\`. On Windows, use $env:BRIDGESTAN=$pwd.

Python#

In Python we use pytest to run tests. Tests are written using basic assert statements and helper code from numpy.testing.

The Python test suite has the ability to run mutually exclusive groups of code. This is to allow testing of features such as the BRIDGESTAN_AD_HESSIAN flag which change underlying code and therefore cannot be loaded at the same time as models compiled without it.

Running

pytest -v python/

Will run the “default” grouping. To run the other group(s), run

pytest --run-type=ad_hessian -v python/

The set up for this can be seen in tests/conftest.py and is based on the Pytest documentation examples.

Julia#

Julia tests are written using the built in unit testing library.

julia --project=./julia -t 2 -e "using Pkg; Pkg.test()"

R#

R tests are written using testthat.

cd R/
Rscript -e "devtools::test()"

The R unit tests are much more basic than the Python or Julia tests.

Rust#

The Rust tests can be run with cargo

cd rust/
cargo test