AfterAll global hook cucumber-jvm

前端 未结 2 1747
南笙
南笙 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 08:57

    As of Cucumber 2.4.0, the following class gave me the equivalent of @BeforeClass in Junit.

    You can place this in test/java/cucumber/runtime.

    package cucumber.runtime; //cannot change.  can be under /test/java
    
    import cucumber.runtime.io.ResourceLoader;
    import cucumber.runtime.snippets.FunctionNameGenerator;
    import gherkin.pickles.PickleStep;
    
    import java.util.List;
    
    public class NameThisClassWhatever implements Backend {
        private Glue glue;
        private List gluePaths;
    
        @Override
        public void loadGlue(Glue glue, List gluePaths) {
            this.glue = glue;
            this.gluePaths = gluePaths;
    
            //Any before steps here
        }
    
        @Override
        public void disposeWorld() {
            //any after steps here
        }
    
        @Override
        public void setUnreportedStepExecutor(UnreportedStepExecutor executor) { }
    
        @Override
        public void buildWorld() { }
    
        @Override
        public String getSnippet(PickleStep p, String s, FunctionNameGenerator fng) {
            return null;
        }
    
        public NameThisClassWhatever(ResourceLoader resourceLoader)  { }
    }
    

提交回复
热议问题