1

Question:

In a java-project, I can write an integration test involving a database:

  1. Clean up all the data in the table that is currently available.
  2. Upload new test data. Do a test on them.
  3. Make a rollback. All this with Java @Transactional.

Can I do something (Transactional) similar in karate?

Now my algorithm in karate is:

  1. Insert test data into the database from karate.
  2. Call api java method that works with data. Problem: The tables already have data that interferes with the test. And you can’t delete them forever for the test.
Raccoon21
  • 21
  • 3

1 Answers1

1

You can integrate any Java code into Karate, so if you really want you can go direct to JDBC.

When it comes to APIs I'm pretty sure you can't control transactions, because you are at an outer layer of the architecture. From experience, the strategy I've seen work is that each test creates data that is "scoped" to that flow at the start. When you GET data, you can filter by the data you are interested in either by the API parameters, or you can do it in Karate (typically a match contains when arrays are involved).

You can see a typical example here.

Also see this thread: https://stackoverflow.com/a/60944060/143475

Peter Thomas
  • 54,465
  • 21
  • 84
  • 248