Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Converting Xtext DSL tests to Junit5
Converting Xtext DSL tests to Junit5 [message #1848193] Wed, 24 November 2021 15:41 Go to next message
Lars Gelin is currently offline Lars GelinFriend
Messages: 4
Registered: November 2012
Junior Member
We are converting the Junit tests of our Xtext based DSL from Junit4 to JUnit5.
The tests in this test suite is extending the Xtext testing class
org.eclipse.xtext.testing.AbstractLanguageServerTest


It was straight forward to get the test suites to run correctly using JUnit5 within Eclipse (2020-06), i.e. to run it with "Run as JUnit Test".

However, when running the test suite in Maven it does not work. Have tried to follow the advice given in different internet posts, but don't get it right anyway. For example:

wiki.eclipse.org/Tycho/How_Tos/JUnit5
And
blogs.itemis.com/en/xtext-2.14-adds-support-for-junit-5

The error we get looks like this:
runTest: 212->AbstractCbbLspTest.testValidation:139->AbstractLanguageServerTest.initializeContext:1132->AbstractLanguageServerTest.initialize:340->AbstractLanguageServerTest.initialize:353->AbstractLanguageServerTest.lambda$initialize$1:348 » NullPointer 


Running it in the debugger indicates that there is some problem with the execution of the @Before / @BeforeEach functions. The NullPointer above is a result of that the AbstractLanguageServerTest.setup() function isn't executed before the test case starts.

Also, when running in the debugger, I noticed that the class files of the org.junit.jupiter.engine package used when running with Maven does not seem to match the class files of the org.junit.jupiter.engine package that is used in Eclipse (version 5.6.0).

Our environment:
Eclipse 2020-06
Maven version 3.8.2
Maven compiler plugin version 3.8.1
Maven surefire plugin version 2.22.2
Junit 5 version 5.6.0
Java 11.0.1-1 (but we target Java 8 in our builds)
Tycho version 2.5.0
Xtext version 2.22.0
mwe2-launch-version 2.11.3

Due to a dependency that we don't control, we can't easily use versions later than Xtext 2.22.0 as we are bound to use Eclipse 2020-06 main release.

Any hints pointing me in the right direction are most welcome.

Best regards
Lars Gelin
-------------------------

Our Tycho configuration from the pom.xml of our Xtext Junit test suite:
      <plugin> 
        <groupId>org.eclipse.tycho</groupId> 
        <artifactId>tycho-surefire-plugin</artifactId> 
        <version>${tycho-version}</version> 
        <extensions>false</extensions> 
        <configuration> 
          <useUIHarness>false</useUIHarness> 
          <useUIThread>false</useUIThread> 
          <includes> 
            <include>**/*Test.java</include> 
          </includes> 
          <redirectTestOutputToFile>true</redirectTestOutputToFile> 
          <runOrder>alphabetical</runOrder> 
          <testRuntime>default</testRuntime> 
          <argLine>-ea</argLine> 
        </configuration> 
      </plugin> 
Re: Converting Xtext DSL tests to Junit5 [message #1848196 is a reply to message #1848193] Wed, 24 November 2021 19:07 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
why cant you make sure the junit version is the same.
maybe this is better asked in https://github.com/eclipse/tycho/discussions as it seems to be a tycho config problem


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Converting Xtext DSL tests to Junit5 [message #1848197 is a reply to message #1848196] Wed, 24 November 2021 19:17 Go to previous messageGo to next message
Lars Gelin is currently offline Lars GelinFriend
Messages: 4
Registered: November 2012
Junior Member
Hi, thanks for your quick reply. I do believe that we get the correct JUnit version (5.6.0) both in Eclipse and when running from Maven. It seams that the debugger gets confused somehow.

During the evening we discovered a workaround. By adding these two methods in our sub-class to org.eclipse.xtext.testing.AbstractLanguageServerTest our test suite now run fine also with Maven:
  @BeforeEach
  override void setup() {
    super.setup();
  }
  
  @AfterEach
  override void cleanup() {
    super.cleanup();
  }

Would be nice to understand why we need these.
Thanks,
Lars
Re: Converting Xtext DSL tests to Junit5 [message #1848198 is a reply to message #1848197] Wed, 24 November 2021 19:19 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
hmmm i really have no idea. the annotations are there on the superclass

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Converting Xtext DSL tests to Junit5 [message #1848199 is a reply to message #1848198] Wed, 24 November 2021 19:53 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
can you provide what you do inside
testValidation


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Converting Xtext DSL tests to Junit5 [message #1848205 is a reply to message #1848199] Wed, 24 November 2021 21:48 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
baybe its also this problem
https://www.eclipse.org/lists/tycho-user/msg08544.html
https://www.eclipse.org/forums/index.php?t=msg&th=1103807&goto=1827558&#msg_1827558

using pure maven surefire seems to work


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Converting Xtext DSL tests to Junit5 [message #1848212 is a reply to message #1848198] Thu, 25 November 2021 07:47 Go to previous messageGo to next message
Lars Gelin is currently offline Lars GelinFriend
Messages: 4
Registered: November 2012
Junior Member
Yes, I also noticed these annotations on the super class. Strange why they do not take effect in our Maven builds.
Re: Converting Xtext DSL tests to Junit5 [message #1848221 is a reply to message #1848212] Thu, 25 November 2021 11:58 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
i tried to reproduce and see this in the log
java.lang.IllegalStateException: No Xtext languages have been registered. Please make sure you have added the languages's setup class in '/META-INF/services/org.eclipse.xtext.ISetup'
i wonder how you overcome that


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Converting Xtext DSL tests to Junit5 [message #1848222 is a reply to message #1848221] Thu, 25 November 2021 12:23 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
here is my reproducer.

if the baseclass is in project it works,
if baseclass is in mydsl.ide, it works too
if the baseclass is not it works with the override only

https://github.com/cdietrich/xtext-lsp-tests-with-tycho

it also works when i put the baseclass to mydsl.ide
i wonder: is there something wrong with the bytecode shipped by xtext


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de

[Updated on: Thu, 25 November 2021 13:27]

Report message to a moderator

Re: Converting Xtext DSL tests to Junit5 [message #1848303 is a reply to message #1848222] Sat, 27 November 2021 10:56 Go to previous message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
this is can actual bug in P2 metadata of the testing plugin
https://github.com/eclipse/xtext-core/issues/1781

repo with fix https://ci.eclipse.org/xtext/job/xtext-umbrella/job/cd_issue1781/lastSuccessfulBuild/artifact/build/p2-repository/


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de

[Updated on: Sat, 27 November 2021 11:13]

Report message to a moderator

Previous Topic:Maven Build Issues - Xtext 2.22 2020-06 Java11
Next Topic:Compile into Native using GraalVM
Goto Forum:
  


Current Time: Tue Apr 16 20:00:57 GMT 2024

Powered by FUDForum. Page generated in 0.44460 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top