Making the tests consistent
Let's go back to our test and add the following piece of code:
@BeforeEach fun setup() { DB.connect() transaction { SchemaUtils.drop(CatsTable) } }
Here, we are using the @BeforeEach
annotation on a function. As its name suggests, this code will run before each test. The function will establish a connection to the database and drop the table completely. Then, our application will recreate the table.
Now, our tests should pass consistently. In the next section, we'll learn how to fetch a cat from the database using the Exposed library.