Skip to main content



      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 08:19 Go to next message
Eclipse UserFriend
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 15:23 Go to previous messageGo to next message
Eclipse UserFriend
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);
	}
}
Re: Grammar and Validation unit_testing [message #1237475 is a reply to message #1237474] Wed, 29 January 2014 15:23 Go to previous message
Eclipse UserFriend
P.S: which xtext version do you use? i tested with 2.4.3 and 2.5.0

[Updated on: Wed, 29 January 2014 15:29] by Moderator

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


Current Time: Wed Jul 23 16:43:04 EDT 2025

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

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

Back to the top