Skip to content

JUnit test reports don't preserve empty spaces #3723

@trancexpress

Description

@trancexpress

See: https://download.eclipse.org/eclipse/downloads/drops4/I20260318-1800/testresults/html/org.eclipse.jdt.ui.tests_ep440I-unit-macosx-x86_64-java21_macosx.cocoa.x86_64_21.html

E.g. reported failure:

contents was not formated. Actual: package test1; public class E1 { public void foo( Object o ) { String s = (String)o; } }

java.lang.AssertionError: contents was not formated. Actual: package test1;
public class E1 {
public void foo( Object o ) {
String s = (String)o;
}
}
at org.junit.Assert.fail(Assert.java:89)
at org.junit.Assert.failEquals(Assert.java:187)
at org.junit.Assert.assertNotEquals(Assert.java:163)
at org.eclipse.jdt.ui.tests.quickfix.SaveParticipantTest.assertChangedFromTo(SaveParticipantTest.java:986)
at org.eclipse.jdt.ui.tests.quickfix.SaveParticipantTest.testFormatAll01(SaveParticipantTest.java:138)
at java.base/java.lang.reflect.Method.invoke(Method.java:580) 
Image

There are 3 important contents in the test:

		String fileOnDisk= """
			package test1;
			public class E1 {
			    public void foo( Object o ) {
			        String s= (String)o;
			    }
			}""";
		String fileOnEditor= """
			package test1;
			public class E1 {
			    public void foo( Object o ) {
			        String s    = (String)o;
			    }
			}""";
		String expected1= """
			package test1;
			public class E1 {
			    public void foo(Object o) {
			        String s = (String) o;
			    }
			}""";

The test source is created with fileOnDisk contents. Then its changed in an editor to fileOnEditor, then save actions are expected to result in content expected1.

The JUnit report seems to remove leading empty spaces, seen immediately in the report.

Sequences of empty spaces seem to be reduced to a single empty space, which is harder to sport in the report. String s = (String)o; is coming from fileOnEditor, since expected1 was not the actual content - otherwise the test would not fail. But then the actual contents must be String s = (String)o;.

This actually makes failures where strings are compared hard to understand.

It does seem to be an issue with how the HTML content is displayed, since the HTML content does have the empty spaces:

            <tr valign="top" class="Error">
                <td>[{0}]</td><td title="[{0}]">testFormatAll01[{0}]</td><td>Failure</td><td>contents was not formated. Actual: package test1; public class E1 {     public void foo( Object o ) {         String s    = (String)o;     } }<code>
                        <br>
                        <br>
                        java.lang.AssertionError: contents was not formated. Actual: package test1;
                        <br>
                        public class E1 {
                        <br>
                            public void foo( Object o ) {
                        <br>
                                String s    = (String)o;
                        <br>
                            }
                        <br>
                        }
                        <br>
                        	at org.junit.Assert.fail(Assert.java:89)
                        <br>
                        	at org.junit.Assert.failEquals(Assert.java:187)
                        <br>
                        	at org.junit.Assert.assertNotEquals(Assert.java:163)
                        <br>
                        	at org.eclipse.jdt.ui.tests.quickfix.SaveParticipantTest.assertChangedFromTo(SaveParticipantTest.java:986)
                        <br>
                        	at org.eclipse.jdt.ui.tests.quickfix.SaveParticipantTest.testFormatAll01(SaveParticipantTest.java:138)
                        <br>
                        	at java.base/java.lang.reflect.Method.invoke(Method.java:580)
                        <br>
                    </code></td><td>0.105</td>
            </tr>

org.eclipse.jdt.ui.tests_ep440I-unit-macosx-aarch64-java21_macosx.cocoa.aarch64_21.zip

Metadata

Metadata

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions