Skip to main content



      Home
Home » Modeling » TMF (Xtext) » Problems using AbstractLanguageServerTest
Problems using AbstractLanguageServerTest [message #1791888] Fri, 06 July 2018 10:59 Go to next message
Eclipse UserFriend
I created a new DSL with the Xtext wizard. I selected language server, Gradle build and JUnit 5 support.

I added a language server test in the <mydsl>.ide project in the source folder src/test/java.

The test class sublasses the AbstractLanguageServerTest and gives the language id in the constructor.

All my tests fail because of this NPE:

java.lang.NullPointerException
	at org.eclipse.xtext.testing.AbstractLanguageServerTest.lambda$initialize$1(AbstractLanguageServerTest.java:289)
	at org.eclipse.xtext.xbase.lib.ObjectExtensions.operator_doubleArrow(ObjectExtensions.java:139)
	at org.eclipse.xtext.testing.AbstractLanguageServerTest.initialize(AbstractLanguageServerTest.java:291)
	at org.eclipse.xtext.testing.AbstractLanguageServerTest.initialize(AbstractLanguageServerTest.java:281)
	at org.eclipse.xtext.testing.AbstractLanguageServerTest.initializeContext(AbstractLanguageServerTest.java:814)
	at org.eclipse.xtext.testing.AbstractLanguageServerTest.testCompletion(AbstractLanguageServerTest.java:775)
	at de.abas.screen.ls.ide.tests.completion.ScreenServiceCompletionTest.testEndCompletion(ScreenServiceCompletionTest.java:23)


I use Eclipse Photon and Xtext 2.14.0.
I fixed the build already like it is mentioned here: https://github.com/eclipse/xtext/issues/1231

My DSL is just the Greetings tutorial DSL and one of the failing tests is this:
@Test
	def void test02_openFile() {
		initialize()

		val file = 'hello.mydsl'.writeFile("")
		file.open('''
			Hello Xtext!
		''')

		Assertions.assertTrue(diagnostics.get(file).empty, "There're issues in file 'hello.mydsl'.")
	}



Everything works but not my test. What am I doing wrong?
Re: Problems using AbstractLanguageServerTest [message #1791890 is a reply to message #1791888] Fri, 06 July 2018 11:16 Go to previous messageGo to next message
Eclipse UserFriend
Hi,

can you please give more context. i cannot reproduce.

(1) did you add the mydsl.ide project to the test project
(2) is lsp4j and lsp4j.jsonrpc on the dependencies of your test project?
Re: Problems using AbstractLanguageServerTest [message #1791891 is a reply to message #1791890] Fri, 06 July 2018 11:19 Go to previous messageGo to next message
Eclipse UserFriend
besides that: debugging always helps to analyse
Re: Problems using AbstractLanguageServerTest [message #1791892 is a reply to message #1791891] Fri, 06 July 2018 11:26 Go to previous messageGo to next message
Eclipse UserFriend
Attached is my build.grade of the <mydsl>.ide project.
  • Attachment: build.gradle
    (Size: 1.97KB, Downloaded 107 times)
Re: Problems using AbstractLanguageServerTest [message #1791893 is a reply to message #1791892] Fri, 06 July 2018 11:27 Go to previous messageGo to next message
Eclipse UserFriend
i miss e.g.

compile project(':de.abas.screen.ls.ide')
Re: Problems using AbstractLanguageServerTest [message #1791894 is a reply to message #1791893] Fri, 06 July 2018 11:29 Go to previous messageGo to next message
Eclipse UserFriend
I added the test to the project de.abas.screen.ls.ide itself.
Re: Problems using AbstractLanguageServerTest [message #1791895 is a reply to message #1791894] Fri, 06 July 2018 11:35 Go to previous messageGo to next message
Eclipse UserFriend
I added a screenshot of my project layout.
Re: Problems using AbstractLanguageServerTest [message #1791896 is a reply to message #1791895] Fri, 06 July 2018 11:42 Go to previous messageGo to next message
Eclipse UserFriend
When I debug I can see that the field languageServer of the class AbstractLanguageServerTest is always null. What could be the problem?
Re: Problems using AbstractLanguageServerTest [message #1791897 is a reply to message #1791894] Fri, 06 July 2018 11:43 Go to previous messageGo to next message
Eclipse UserFriend
i still cannot reproduce.
are you sure you got language id and file extension correct?
Re: Problems using AbstractLanguageServerTest [message #1791898 is a reply to message #1791897] Fri, 06 July 2018 11:45 Go to previous messageGo to next message
Eclipse UserFriend
Do you recommend to add an extra test project or is it ok to add the test inside the test source folder of the <mydsl>.ide project?
Re: Problems using AbstractLanguageServerTest [message #1791899 is a reply to message #1791898] Fri, 06 July 2018 11:46 Go to previous messageGo to next message
Eclipse UserFriend
it is ok i tried both and it works fine

package org.xtext.example.mydsl3.tests

import org.eclipse.xtext.testing.AbstractLanguageServerTest
import org.junit.Assert
import org.junit.Test

class MyTest extends AbstractLanguageServerTest {
	new() {
		super("mydsl3")
	}
	
	@Test
	def void test02_openFile() throws Exception {
		initialize();

		val file = 'hello.mydsl3'.writeFile("")
		file.open('''
			Hello Xtext!
		''')

		Assert.assertTrue("There're issues in file 'hello.mydsl'.", diagnostics.get(file).empty)
	}
	
}
Re: Problems using AbstractLanguageServerTest [message #1791900 is a reply to message #1791899] Fri, 06 July 2018 11:49 Go to previous messageGo to next message
Eclipse UserFriend
How does your build.gradle file look like?
Re: Problems using AbstractLanguageServerTest [message #1791901 is a reply to message #1791900] Fri, 06 July 2018 11:52 Go to previous messageGo to next message
Eclipse UserFriend
no change besides the workaround for signature exception.

=> i am sure you have the wrong file extension
Re: Problems using AbstractLanguageServerTest [message #1791902 is a reply to message #1791901] Fri, 06 July 2018 11:55 Go to previous messageGo to next message
Eclipse UserFriend
I also have this test and this does not work either:

@Test
	def void testEndCompletion() {

		testCompletion[
			model = '''Hello Xtext'''
			line = 0
			column = 10
			expectedCompletionItems = '''!'''

		]
	}
Re: Problems using AbstractLanguageServerTest [message #1791903 is a reply to message #1791901] Fri, 06 July 2018 11:56 Go to previous messageGo to next message
Eclipse UserFriend
can you please share your complete hello world project
Re: Problems using AbstractLanguageServerTest [message #1791905 is a reply to message #1791903] Fri, 06 July 2018 11:59 Go to previous messageGo to next message
Eclipse UserFriend
I packed everything as ZIP archive and removed the .gradle folder.
Re: Problems using AbstractLanguageServerTest [message #1791906 is a reply to message #1791905] Fri, 06 July 2018 12:12 Go to previous message
Eclipse UserFriend
you use junit 5 .
abstractlanguageservertest does not support that.
please open a bug at xtext-core

workaround:

class AbstractScreenServiceLSPTest extends AbstractLanguageServerTest {
	
	new() {
		super('screenservice')
	}
	
	@Before @BeforeEach
	override void setup() {
		super.setup()
	}
Previous Topic:Inheritance from non-grammar java class
Next Topic:Formatting Scientific Notation
Goto Forum:
  


Current Time: Sat Jun 14 14:12:11 EDT 2025

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

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

Back to the top