1

Im trying to start my Spring Boot Application from a JUnit suite class but the application isnt starting. My suite class calls two test classes, each test class makes API calls to the Spring Boot Application

  1. BasicParallelKarateTest
  2. DynamicParallelKarateTest

Both of these test classes will pass using mvn clean install on the root POM but will fail in the same execution when being called from the SuiteRunner class.

Suite class

import com.intuit.karate.KarateOptions;
import com.intuit.karate.junit4.Karate;
import org.junit.runner.RunWith;
import org.junit.runners.Suite;

    @RunWith(Karate.class)
    @Suite.SuiteClasses({
            BasicParallelKarateTest.class,
            DynamicParallelKarateTest.class
    })
    @KarateOptions(tags = "~@ignore")
    public class JUnitSuiteTest { }

Build - mvn clean install

enter image description here

Stack Trace

[ERROR] Errors: 
[ERROR]   BattleTest.feature:11 - 
org.apache.http.conn.HttpHostConnectException: Connect to localhost:8080 [localhost/127.0.0.1] failed: Connection refused (Connection refused)
...
...
...
[ERROR]   ResultTest.feature:10 - 
org.apache.http.conn.HttpHostConnectException: Connect to localhost:8080 [localhost/127.0.0.1] failed: Connection refused (Connection refused)
[ERROR] Tests run: 13, Failures: 0, Errors: 13, Skipped: 0

Repo : https://github.com/cmccarthyIrl/spring-karate-test-harness

Partial Solution - doesnt run suite class in CI

    @KarateOptions(tags = "~@ignore")
@RunWith(JUnitPlatform.class)
@SelectClasses({
        BasicParallelKarateTest.class,
        DynamicParallelKarateTest.class
})
@IncludeEngines({"junit-jupiter","junit-vintage"})
public class JUnitSuiteTest {}
KahunaDub
  • 89
  • 1
  • 8

1 Answers1

1

Add a SpringClassRule and SpringMethodRule in your tests

public class MyTest {

    @ClassRule
    public static final SpringClassRule springClassRule = new SpringClassRule();

    @Rule
    public final SpringMethodRule springMethodRule = new SpringMethodRule();

Other alternative is run your tests suite with @RunWith(SpringRunner.class), but the suite can't have two test runner, so you would have to remove the @RunWith(Karate.class). I guess this isn't an option, right?

Rodrigo
  • 2,313
  • 2
  • 15
  • 23
  • I tried using SpringClassRule and SpringMethodRule but it didnt help. The tests still execute without the application starting. Yeah, I've to stick with the @RunWith(Karate.class) to pick up the Karate tests – KahunaDub Nov 02 '20 at 23:16
  • we're not going to support JUnit4 – Peter Thomas Nov 03 '20 at 01:48