简体   繁体   English

我如何添加信息以在mvn和jenkins中运行时进行测试?

[英]How I can add information to test when it run with mvn and in jenkins?

I have unit tests in Java, and I want to add some information on the test to the log. 我有Java单元测试,我想将有关测试的一些信息添加到日志中。

I want to do it with Maven - mvn clean install –Pstaging , and also in Jenkins 我想用Maven- mvn clean install –Pstaging ,也要在Jenkins中做

I tried to do it with Logger : 我试图用Logger做到这一点:

       private static final Logger LOG = LoggerFactory.getLogger(S2STest.class); and then  
     LOG.info("message")

and Added it to the pom.xml 并将其添加到pom.xml

<dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-api</artifactId>
        <version>1.7.6</version>
        <scope>provided</scope>
    </dependency>    

However, I didn't see any information when I run the test. 但是,运行测试时没有看到任何信息。

How I can add information to the test in Maven and Jenkins? 如何在Maven和Jenkins中为测试添加信息?

Jenkins doesn't include an SLF4J implementation by default. Jenkins默认不包含SLF4J实现。 You can see that in their pom : 您可以在他们的pom看到:

  <dependency>
    <groupId>org.slf4j</groupId>
    <artifactId>slf4j-api</artifactId>
    <version>${slf4jVersion}</version>
  </dependency>
  <dependency>
    <groupId>org.slf4j</groupId>
    <artifactId>slf4j-nop</artifactId>
    <version>${slf4jVersion}</version>
  </dependency>
  <dependency>
    <groupId>org.slf4j</groupId>
    <artifactId>slf4j-jdk14</artifactId>
    <version>${slf4jVersion}</version>
  </dependency>
  <dependency>
    <groupId>org.slf4j</groupId>
    <artifactId>jcl-over-slf4j</artifactId>
    <version>${slf4jVersion}</version>
  </dependency>
  <dependency>
    <groupId>org.slf4j</groupId>
    <artifactId>log4j-over-slf4j</artifactId>
    <version>${slf4jVersion}</version>
  </dependency>
  <dependency>
    <groupId>commons-logging</groupId>
    <artifactId>commons-logging</artifactId>
    <version>1.1.3</version>
  </dependency>

So, what you need to do is include your own SLF4J implementation in your own pom, such as Log4J or Logback , OR configure it to use the slf4j-jdk14 implementation by using Logger.addHandler . 因此,您需要做的是在自己的pom中包含自己的SLF4J实现,例如Log4JLogback ,或者通过使用Logger.addHandler将其配置为使用slf4j-jdk14实现。 In the first two cases, you will also have to configure that framework's appropriate configuration files as well. 在前两种情况下,您还必须配置该框架的适当配置文件。

Once you have turned on whichever of these logging frameworks you've decided, you will be able to use that configuration to generate a target for the logging information, and you will have the file. 一旦确定了这些日志记录框架中的任何一个,就可以使用该配置生成日志记录信息的目标,并且您将拥有该文件。 However, getting into the details of exactly how to do that is too broad of a question for Stack Overflow; 然而,对于如何进行堆栈溢出,深入了解确切的操作方法是一个太宽泛的问题。 I recommend picking one and reading their tutorials. 我建议选择一个并阅读其教程。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM