#Test harnesses

10 messages · Page 1 of 1 (latest)

hasty slate
#

How do you organise a group of dependent integration tests?

Consider ITs for a web service. I start with (1) to test user creation where I want to assert that the returned JWT is valid and the user was created in the db, and then my next test (2) uses that JWT do try and do some action that only an authenticated user can do and finally (3) now I want to use that JWT to logout.

I could pile all this into a single test and then group steps into fn's passing values between them as a mutable struct ... but that feels quiet manual and I given a lot of languages have richer test harnesses I assumed something would exist in the rust ecosystem?

steep meteor
hasty slate
#

A few ideas that spring to mind:

  • being able to group tests into a 'suite'
  • being able to control execution order (ie I want registration to occur before login)
  • before/after test hooks
  • beforeAll / afterAll test hooks
  • some way to pass context/state through a test suite
steep meteor
#

Grouping tests into a suite is easily done with modules

#

Just put them all into a module

#

Controlling execution order is impossible and against the conceptual model of Cargo tests

#

Tests must run independently (so they can be parallelized) and they must not have dependencies on each other

#

Again, before/after test hooks: Use RAII (i.e. cleanup should be done on Drop, and you can just write the code to initialize the world inside the test itself)

amber vessel
#

Think of the thing you are testing not as "each operation on a JWT" (several tests) but as "the entire lifecycle of a JWT" (one test)