Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Multiple unittest files to be executed by Maven(Execute multiple unittest files when working with Maven)
Multiple unittest files to be executed by Maven [message #1805444] Mon, 15 April 2019 11:34 Go to next message
Christoph Brewing is currently offline Christoph BrewingFriend
Messages: 3
Registered: April 2019
Junior Member
I have an Xtext project, say org.xtext.example.mydsl. I try to convert it to a headless one. In particular, I would like it to be built and tested based on Maven.

Given I want to maintain the unittests of sub-project org.xtext.example.mydsl.tests in the form of multiple files. For example, given I have the following two files

  1. MyDslParsingTest.xtend (Generated during workflow execution)
  2. MyDslWHATEVERTest.xtend (Manual copy paste of the file above)

When I run
 mvn clean verify
in the directory of the parent project, org.xtext.example.mydsl.parent

Then only the tests of the first file, MyDslParsingTest.xtend, are executed.

What do I have to do in order to let Maven also execute the tests of the manually crafted file, MyDslWHATEVERTest.xtend?
Re: Multiple unittest files to be executed by Maven [message #1805520 is a reply to message #1805444] Tue, 16 April 2019 15:56 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
Can you please provide a complete minimal sample

(Also have a look what the wizard creates if you select maven)


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

[Updated on: Tue, 16 April 2019 15:57]

Report message to a moderator

Re: Multiple unittest files to be executed by Maven [message #1805567 is a reply to message #1805520] Wed, 17 April 2019 14:00 Go to previous messageGo to next message
Christoph Brewing is currently offline Christoph BrewingFriend
Messages: 3
Registered: April 2019
Junior Member
At least, I solved the symptoms of my issue. However, I have to admit that I do not understand the solution. Here is the review:

The symptom was that only those unittests were executed by Maven which were part of the original (auto generated) file, e.g. MyDslParsingTest.xtend.

Unittests of other files, e.g. MyDslWHATEVERTest.xtend, were not considered by Maven at all. Eventually, I compared the two file types and discovered differences in the "setup" (I mean: imports and injections).

Unittests in this file are executed by Maven: MyDslParsingTest.xtend
import com.google.inject.Inject
import org.eclipse.xtext.testing.InjectWith
import org.eclipse.xtext.testing.extensions.InjectionExtension
import org.eclipse.xtext.testing.util.ParseHelper
import org.example.hellomaven.helloMaven.Model
import org.junit.jupiter.api.Assertions
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.^extension.ExtendWith

@ExtendWith(InjectionExtension)
@InjectWith(HelloMavenInjectorProvider)
class HelloMavenParsingTest {
	@Inject ParseHelper<Model> parseHelper
       
        @Test
         ...


Unittests in this file are NOT executed by Maven: MyDslWHATEVERTest.xtend
import com.google.inject.Inject
import org.eclipse.xtext.testing.InjectWith
import org.eclipse.xtext.testing.XtextRunner
import org.eclipse.xtext.xbase.testing.CompilationTestHelper
import org.junit.Test
import org.junit.runner.RunWith

import static org.junit.Assert.*

@RunWith(typeof(XtextRunner))
@InjectWith(typeof(SismicInjectorProvider))
class HelloMavenWHATEVERTest {
	@Inject extension CompilationTestHelper

        @Test
        ...


The "setup" of the latter, I finally modified it to the following:

Unittests in this file ARE now executed by Maven: MyDslWHATEVERTest.xtend
import com.google.inject.Inject
import org.eclipse.xtext.testing.InjectWith
import org.eclipse.xtext.testing.extensions.InjectionExtension
import org.eclipse.xtext.xbase.testing.CompilationTestHelper
import org.eclipse.xtext.testing.XtextRunner
import org.junit.runner.RunWith

import org.junit.jupiter.api.Assertions
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.^extension.ExtendWith

@ExtendWith(InjectionExtension)
@InjectWith(SismicInjectorProvider)
class SismicGenerationTest implements completeScenarioWithFrancaReferences {
	@Inject extension CompilationTestHelper
     
  @Test 
        ...

The thrilling thing for me was that in the Eclipse IDE, I could launch all tests from all files. Everything was working. However, Maven had a different perspective ...



Re: Multiple unittest files to be executed by Maven [message #1805569 is a reply to message #1805567] Wed, 17 April 2019 14:03 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
looks like you mix junit4 and junit5.
is there any reason?
if you want junit4 use it everywhere
if you want junit5 use it everywhere
otherwise you should research
how to to both with maven and or tycho


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

[Updated on: Wed, 17 April 2019 14:04]

Report message to a moderator

Re: Multiple unittest files to be executed by Maven [message #1805571 is a reply to message #1805569] Wed, 17 April 2019 14:14 Go to previous messageGo to next message
Christoph Brewing is currently offline Christoph BrewingFriend
Messages: 3
Registered: April 2019
Junior Member
When I "experimented" with the test files today, from time to time I got error messages from Eclipse which support your statement.

No, there is no specific reason for mixing junit4 and junit5. When I developed the tests, I was so involved in my "domain specific problems" that I did not notice.

Thanks for your time and your hint, Christian.
Re: Multiple unittest files to be executed by Maven [message #1805572 is a reply to message #1805571] Wed, 17 April 2019 14:15 Go to previous message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
=> you use junit5 for all.
or recreate and use junit4 everywhere


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Previous Topic:Parsing doxygen with xtext
Next Topic:1001 tips and tricks for Xtext
Goto Forum:
  


Current Time: Thu Mar 28 23:37:00 GMT 2024

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

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

Back to the top