1

I have a GraphQL service that i'm using Karate to test. I have a feature for mutations and a couple features for queries. I'm doing a Spring Boot integration test, like so

@SpringBootTest(classes=ApplicationTest.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)

public class RunUnitCukeTest implements InitializingBean {
@LocalServerPort
int port;

@Karate.Test
Karate runTest() {
    return new Karate()//
            .feature("classpath:features/TestMutationsAndDatabaseSetup.feature")
            .feature("classpath:features/Queries.feature");
}

My thinking is, rather than staging a bunch of data into my H2 database in code, I could instead just test my mutations first (thus staging some data), and then test my queries/the calculations those queries need to do.

When my mutations feature runs, everything works fine. But my Queries feature isn't seeing any data. Which makes me wonder if they're running in the opposite order as I want, and if there's any way to get them to run sequentially.

Steve
  • 4,457
  • 12
  • 48
  • 89

1 Answers1

1

Well, perhaps you should read this first: https://stackoverflow.com/a/46080568/143475

Maybe what you should do is use karate.callSingle() in the karate-config.js to do the mutations, and then kick off the rest of the tests.

Yes, Karate is designed to run tests in parallel and force you to NOT have dependencies across your Scenario-s, let alone Feature-s.

Note that the @Karate.Test annotation is NOT the recommended way to run test-suites in CI: https://stackoverflow.com/a/65578167/143475 - and I don't think it honors the order in which you call feature().

If the mutation flows are pure "set up", just call it in your JUnit code before running your "main" suite: https://stackoverflow.com/a/60944060/143475

Peter Thomas
  • 54,465
  • 21
  • 84
  • 248
  • I'm using the Karate.Test annotation because I want Karate to start up after I've created the Spring Context. Correct me if I'm wrong, but if I let Karate start up automatically, karate-config.js would execute before Spring would be able to stand up my database. – Steve Oct 07 '21 at 19:17
  • @Steve if you use the `Runner` API - you are free to start Karate any time and not be restricted by the weird JUnit / Spring annotation life-cycle. I'll also say that `@Karate.Test` is not designed or suited for CI. also refer: https://stackoverflow.com/a/51178439/143475 – Peter Thomas Oct 07 '21 at 19:32