1

Following this sample mentioned in the Karate 1.0 upgrade guide I wrote this simple test class:

package feature;

import com.intuit.karate.RuntimeHook;
import com.intuit.karate.Suite;

import com.intuit.karate.Results;
import com.intuit.karate.Runner;
import static org.junit.jupiter.api.Assertions.*;

public class KarateTest implements RuntimeHook {

    private static final int THREAD_COUNT = 1;

    @Override
    public void beforeSuite(Suite suite)
    {
        System.out.println("########## beforeSuite() is fired! ##########");
    }

    @Test
    public void testParallel() {
        
        Results results = Runner.path("classpath:feature")
        .parallel(THREAD_COUNT);

        assertEquals(0, results.getFailCount(), results.getErrorMessages());
    }
        
    @Override
    public void afterSuite(Suite suite)
    {
        System.out.println("########## afterSuite() is fired! ##########");
    }

}

I expected to see the lines printed by the beforeSuite() and afterSuite() methods appearing in the logs. The test ran successfully, but the hooks did not seem to trigger. What did I miss?

Drunda Nibel
  • 101
  • 6
  • please follow this process: https://github.com/intuit/karate/wiki/How-to-Submit-an-Issue – Peter Thomas Sep 20 '21 at 17:48
  • In my opinion the duplicate flag ist wrong, because my question has nothing to do with the Karate hooks which can be used within feature files. Instead, I need to be able to run an afterSuite() routine in particular to tear down a Docker environment after all tests in all features have been finished. As far as I can see, the Karate hooks used in feature files do not support such approach. – Drunda Nibel Sep 20 '21 at 18:15
  • you are supposed to read the links in the answer(s) - anyway, if `afterSuite()` is not working for you, it works for others. so there is no other way for anyone to help you - but by the way, you seem to have missed calling `Runner.hook()` ? – Peter Thomas Sep 20 '21 at 18:39
  • Where can I find this Runner.hook()? In the [sample](https://github.com/kirksl/karate-maven-gradle/blob/5c4580372dc6f067bdb6aebb5803ac166b9111f5/src/test/java/KarateHook.java) I don't see it. – Drunda Nibel Sep 20 '21 at 19:00
  • 1
    yes, this expects you to be familiar with the Java API of the `Runner`. e.g. `rb.hook(new KarateTest());` please take the help of a Java programmer if possible, see this line: https://github.com/kirksl/karate-maven-gradle/blob/5c4580372dc6f067bdb6aebb5803ac166b9111f5/src/test/java/KarateRunner.java#L21 – Peter Thomas Sep 20 '21 at 19:08
  • 1
    Ok, thanks. I now solved it by following this example (but with implementing RuntimeHook instead of the older ExecutionHook): https://github.com/peterquiel/karate-experiment/blob/master/src/test/groovy/com/github/peterquiel/karate/experiment/hook/ExecutionHookExampleTest.groovy – Drunda Nibel Sep 20 '21 at 20:32

0 Answers0