Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Grammar and Validation unit_testing(Unit_testing of the validator for my language)
Grammar and Validation unit_testing [message #1236949] Tue, 28 January 2014 13:19 Go to next message
Juliane Mueller is currently offline Juliane MuellerFriend
Messages: 30
Registered: August 2011
Member
Dear all,

I want to test my xText grammar and the related validator.
Therefor I've found the very good tutorial on this URL: http://code.google.com/a/eclipselabs.org/p/xtext-utils/wiki/Unit_Testing
and implemented it for my grammar.

For me it is very important to test the validator for my language.
In case I have a test abstact looking like this:
public class CalculationGrammarTest extends XtextTest {
	private static final String warningFile = "calculationModel2.calculation";
	private static final String path = "D:\\abc\\resources\\ModelFileTest\\"


	public CalculationGrammarTest() {
		super(path);
	}
	
	@Test
	public void warningCalculationTest() {
		testFile(warningFile);
	}
	
	@Test
	public void warningCalculationTest2() {
		testFile(warningFile);
        }
}


I've also changed something in XtextTest.java. The changed modules are:
if (!resourceRoot.contains(":\\")) {
in the constructor and I'm using the method
URI.createFileURI
instead of URI.createURI.


The validator is called in warningCalculationTest, but NOT in warningCalculationTest2. Has anyone an idea why this strange behavior happens? I need the validator in every testcase.

I'm looking forward for your reply!
Best regards, Juliane
Re: Grammar and Validation unit_testing [message #1237474 is a reply to message #1236949] Wed, 29 January 2014 20:23 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 13661
Registered: July 2009
Senior Member
Hi,

i actually cannot reproduce that.
maybe it has todo with your changes regarding absolute paths.

here is my test that works fine


@RunWith(XtextRunner2.class)
@InjectWith(MyDslInjectorProvider.class)
public class CalculationGrammarTest extends XtextTest {
	private static final String warningFile = "test.mydsl8";
	private static final String noWarningFile = "test2.mydsl8";
	private static final String path = "model";


	public CalculationGrammarTest() {
		super(path);
	}
	
	@Test
	public void warningCalculationTest() {
		testFile(warningFile);
		assertConstraints(
				  issues.warningsOnly()
				        .inLine(1)
				        .oneOfThemContains("Name should start")
				);
	}
	
	@Test
	public void warningCalculationTest2() {
		testFile(warningFile);
		assertConstraints(
				  issues.warningsOnly()
				        .inLine(1)
				        .oneOfThemContains("Name should start")
				);
        }
	
	@Test
	public void warningCalculationTest3() {
		testFile(noWarningFile);
	}
}


Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/it-services/methods-and-tools/xtext
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Grammar and Validation unit_testing [message #1237475 is a reply to message #1237474] Wed, 29 January 2014 20:23 Go to previous message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 13661
Registered: July 2009
Senior Member
P.S: which xtext version do you use? i tested with 2.4.3 and 2.5.0

Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/it-services/methods-and-tools/xtext
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de

[Updated on: Wed, 29 January 2014 20:29]

Report message to a moderator

Previous Topic:grammar for ecore metamodel
Next Topic:how to limit options to scope entities
Goto Forum:
  


Current Time: Thu Nov 26 10:41:55 GMT 2020

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

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

Back to the top