测试运行器 class 不记录任何内容
Test Runner class does not log anything
当我 运行 我用 Maven 命令测试时,这些日志没有打印出来。
你能解释一下为什么吗?
@RunWith(Cucumber.class)
@CucumberOptions(features= "src/test/resources/features/dhlcj", glue="com.dhl.gaqcjqa.fsApi.steps")
public class TestRunnerFsApi extends AbstractTestNGCucumberTests {
static {
Log.info("--------------------------------------------");
Log.info("S T A R T ");
UrlFactory.loadAllResources();
Log.info("E N D ");
Log.info("--------------------------------------------");
int processors = Runtime.getRuntime().availableProcessors();
Log.info("CPU cores: " + processors);
Log.info("--------------------------------------------");
}
}
相反,我得到了一些不必要的信息,例如:
[2020-06-25 21:59:18] [INFO] Loaded: environments/dev >> 1
我在您的代码中发现的第一个问题是您在运行程序中同时使用了 Junit 和 testng。请删除 @Runwith(Cucumber.class) 以便仅使用 testNG。我不知道您在项目中使用哪个依赖项进行日志记录,但我使用了以下依赖项来记录消息。
Maven 依赖:
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>2.13.3</version>
</dependency>
黄瓜赛跑者:
@CucumberOptions(eatures = { "src/test/resources/features" }, glue = { "com.github.frostyaxe.cucumber.stepdefs" } )
public class TestRunner extends AbstractTestNGCucumberTests {
private static Logger log = Logger.getLogger(TestRunner.class);
static {
log.addAppender(new ConsoleAppender(new PatternLayout()));
log.info("--------------------------------------------");
log.info("S T A R T ");
log.info("E N D ");
log.info("--------------------------------------------");
int processors = Runtime.getRuntime().availableProcessors();
log.info("CPU cores: " + processors);
log.info("--------------------------------------------");
}
输出:
--------------------------------------------
S T A R T
E N D
--------------------------------------------
CPU cores: 8
--------------------------------------------
当我 运行 我用 Maven 命令测试时,这些日志没有打印出来。 你能解释一下为什么吗?
@RunWith(Cucumber.class)
@CucumberOptions(features= "src/test/resources/features/dhlcj", glue="com.dhl.gaqcjqa.fsApi.steps")
public class TestRunnerFsApi extends AbstractTestNGCucumberTests {
static {
Log.info("--------------------------------------------");
Log.info("S T A R T ");
UrlFactory.loadAllResources();
Log.info("E N D ");
Log.info("--------------------------------------------");
int processors = Runtime.getRuntime().availableProcessors();
Log.info("CPU cores: " + processors);
Log.info("--------------------------------------------");
}
}
相反,我得到了一些不必要的信息,例如:
[2020-06-25 21:59:18] [INFO] Loaded: environments/dev >> 1
我在您的代码中发现的第一个问题是您在运行程序中同时使用了 Junit 和 testng。请删除 @Runwith(Cucumber.class) 以便仅使用 testNG。我不知道您在项目中使用哪个依赖项进行日志记录,但我使用了以下依赖项来记录消息。
Maven 依赖:
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>2.13.3</version>
</dependency>
黄瓜赛跑者:
@CucumberOptions(eatures = { "src/test/resources/features" }, glue = { "com.github.frostyaxe.cucumber.stepdefs" } )
public class TestRunner extends AbstractTestNGCucumberTests {
private static Logger log = Logger.getLogger(TestRunner.class);
static {
log.addAppender(new ConsoleAppender(new PatternLayout()));
log.info("--------------------------------------------");
log.info("S T A R T ");
log.info("E N D ");
log.info("--------------------------------------------");
int processors = Runtime.getRuntime().availableProcessors();
log.info("CPU cores: " + processors);
log.info("--------------------------------------------");
}
输出:
--------------------------------------------
S T A R T
E N D
--------------------------------------------
CPU cores: 8
--------------------------------------------