user1365697
user1365697

Reputation: 5989

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.

I want to do it with Maven - mvn clean install –Pstaging, and also in Jenkins

I tried to do it with Logger:

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

and Added it to the 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?

Upvotes: 1

Views: 46

Answers (1)

durron597
durron597

Reputation: 32323

Jenkins doesn't include an SLF4J implementation by default. You can see that in their 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. 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.

Upvotes: 1

Related Questions