testing - How to approach integration tests that create new data

91 Views Asked by At

Say I have a test that asserts whether registration of a new user in the system actually succeeds:

RegistrationIntegrationTest#testRegister()

Now, this creates a new test user in the actual database, since I want this test to run on the actual environment. This means that the test must not be run all the time, right? How should I approach these kind of tests? Those that use the actual environment of the system and manipulates real data?

1

There are 1 best solutions below

2
On BEST ANSWER

You could use one of the following:

  1. If possible use an in memmory database like hsqldb, which you can re-create or setup suitably for each TestSuite/TestCase
  2. If the methods under test are transactional, run the test case with spring junit rollback true
  3. If you cannot use 1 or 2, you can write a pre & post test sql script that will setup & then cleanup your db. You can use a framework like dbunit