Search code examples
javaexceptionjunitcucumbercucumber-jvm

Run a JUnit test from my java application


I'm trying to run a Junit test from inside my java application.

this is the JUnit test file

import com.intuit.karate.cucumber.CucumberRunner;
import com.intuit.karate.cucumber.KarateStats;
import cucumber.api.CucumberOptions;
import static org.junit.Assert.assertTrue;
import org.junit.Test;

@CucumberOptions(tags = {"~@ignore"})
public class TestParallel {
    @Test
    public void testParallel() {
        KarateStats stats = CucumberRunner.parallel(getClass(), 5, "target/surefire-reports");
        assertTrue("scenarios failed", stats.getFailCount() == 0);
    }
}

When I try calling it from the main :

public static void main(String[] args) {
    JUnitCore junit = new JUnitCore();
    Result result = junit.run(TestParallel.class);
}

I get this error

java.lang.NoClassDefFoundError: com/intuit/karate/cucumber/CucumberRunner

Any idea how to fix this?


Solution

  • Thank you for your response. I managed to get it to work by deleting

          <scope>test</scope>
    

    from the pom.