无法在黄瓜的Main.main()方法之后运行代码

时间:2018-03-11 15:49:37

标签: cucumber-jvm

有没有办法在Main.main()方法后运行一些代码?

System.out.println("execution start");
Main.main(new String[]{"-g","","./src/main/java/featureDetails/Testing.feature"});
System.out.println("execution over");

在这种情况下,系统无法打印execution over

1 个答案:

答案 0 :(得分:1)

如果查看Main.main()的{​​{3}},您会注意到它包含:System.exit(exitstatus),它会终止系统,然后才能将控制权返回给您的方法并打印消息。< / p>

以编程方式运行命令行的正确方法是使用:

String [] argv = new String[]{ "-g","","./src/main/java/featureDetails/Testing.feature"};
ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader();
byte exitstatus = Main.run(argv, contextClassLoader);