Guy Yafe
Guy Yafe

Reputation: 1021

IntelliJ Idea, Gradle Junit Test - Output Shows Blank Lines

I am running Idea 2020.1.3 Ultimate.

I have created a Gradle project with Gradle 6.5.1 and Junit 5.6.2.

When running a simple test that only prints output to the screen, I see that after each line, Idea adds a blank line. This is making analyzing the results very difficult, since it doubles and triples the output.

This issue doesn't restore when running Gradle from command line.

It does restore when running with TestNG instead of JUnit.

It was also restored with JUnit 4 versions.

Any ideas?

Test Code:

@Test
public void testDummy(){
  System.out.println("line1");
  System.out.println("line2");
  System.out.println("line3");
}

Test output (The blank lines are from the output):

Output:

Testing started at 13:29 ...

> Task :compileJava UP-TO-DATE
> Task :processResources NO-SOURCE
> Task :classes UP-TO-DATE
> Task :compileTestJava UP-TO-DATE
> Task :processTestResources NO-SOURCE
> Task :testClasses UP-TO-DATE

> Task :test

 


line1

line2

line3
    
 

 


Deprecated Gradle features were used in this build, making it incompatible with Gradle 7.0.
Use '--warning-mode all' to show the individual deprecation warnings.
See https://docs.gradle.org/6.5.1/userguide/command_line_interface.html#sec:command_line_warnings

BUILD SUCCESSFUL in 839ms
3 actionable tasks: 1 executed, 2 up-to-date
13:29:19: Task execution finished ':test --tests "org.example.tests.DummyTest.testDummy"'.

build.gradle file:

plugins {
  id 'java'
  id 'idea'
}

group 'org.example'
version '1.0-SNAPSHOT'

repositories {
  mavenCentral()
}

dependencies {
  // https://mvnrepository.com/artifact/org.junit.jupiter/junit-jupiter-engine
  testCompile group: 'org.junit.jupiter', name: 'junit-jupiter-engine', version: '5.6.2'
}

test {
  useJUnitPlatform()
  testLogging {
    outputs.upToDateWhen {false}
    showStandardStreams = true
  }
}

Upvotes: 0

Views: 740

Answers (2)

CrazyCoder
CrazyCoder

Reputation: 402543

It's a known bug. The fix is planned for 2020.3.

Upvotes: 1

theincxption
theincxption

Reputation: 189

I ran your tests from the console and everything was correct. Looks like IntelliJ is adding these blank lines to your output. If you want to get rid of them, consider running your tests from the console (or the IntelliJ terminal).

Anyway, I found a way to trick IntelliJ to stop adding blank lines to your output. Instead of using System.out.println, use System.out.print and then flush the PrintStream. You should use a simple function to do this, like:

private void log(String message) {
    System.out.print(message);
    System.out.flush();
}

and then invoke

log("line1");
log("line2");
log("line3");

which produces the following output:

...
> Task :test




line1
line2
line3

Upvotes: 0

Related Questions