AfterAll global hook cucumber-jvm

前端 未结 2 1746
南笙
南笙 2020-12-21 08:47

I\'m using cucumber-jvm in my integration tests and I need to execute some code after all scenarios are finished, just once.

After reading carefully som

2条回答
  •  青春惊慌失措
    2020-12-21 09:00

    Probably a better way would be to use a build tool, like Ant, Maven or Gradle for set-up and tear-down actions, which are part of integration tests.

    When using Maven Fail Safe Plug-in, for setting up integration tests. There is the phase pre-integration-test, which is typically used for setting up the database and launch the web-container. Then the integration-tests are run (phase integration-test). And afterwards the phase post-integration-test is run, for shutting down and closing / removing / cleaning up things.

    INFO In case the Cucumber tests are run through JUnit, the following might also be worth considering

    In case it is simpler, smaller set up stuff, you can have a look at the JUnit @BeforeClass and @AfterClass. Or implement a JUnit @ClassRule, which has it's own before() and after() methods.

    @ClassRule
    public static ExternalResource resource = new ExternalResource() {
      @Override
      protected void before() throws Throwable {
        myServer.connect();
      }
    
      @Override
      protected void after() {
        myServer.disconnect();
      }
    };
    

提交回复
热议问题