Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » How to Test custom validation with JUnit
How to Test custom validation with JUnit [message #1806991] Mon, 20 May 2019 18:13 Go to next message
Markus Häge is currently offline Markus HägeFriend
Messages: 54
Registered: August 2018
Member
Hi,

I try to test my validation with JUnit.

class MyDslValidator extends AbstractMyDslValidator {
@Check
def checkPosition(CANSignal can){
if(can.pos < 0 || can.pos > 100){
warning("Position out of Range", MyDslPackage.Literals.CAN_SIGNAL__NAME)
}
}

}
This works so far in the Editor. When I edit a greater Value i get the message, Now I want to make a JUnit test for it and fail. I read some but don't find the correct solution. Eclipse says

org.junit.ComparisonFailure: expected:<E[rror : Position]> but was:<E[xpected WARNING 'Position out of Range' on CANSignal at [-1:-1] but got
WARNING (null) 'Position out of Range' on CANSignal, offset 62, length 8

My TestCode (not complete)

@Test
def void validationTest(){

'''
Position 500
'''.parse.assertPosition("Position")
}

def void assertPosition(Domainmodel domainmodel, String string){
domainmodel.assertWarning(MyDslPackage.eINSTANCE.CANSignal, "Position out of Range" ,"Error : " + string )
}

I read in the book of Bettini but don't get it.
How to test it properly? Valid Positions, greater and smaller than the range?

Thanks
Markus
Re: How to Test custom validation with JUnit [message #1806992 is a reply to message #1806991] Mon, 20 May 2019 18:19 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 13117
Registered: July 2009
Senior Member
Am not sure what your actual question is.
Have a look at the signatures of the assert methods and use them

public void assertWarning(org.eclipse.emf.ecore.EObject model,
org.eclipse.emf.ecore.EClass objectType,
java.lang.String code,
java.lang.String... messageParts)

You create the error message without code.


Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/xtext/
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: How to Test custom validation with JUnit [message #1807012 is a reply to message #1806992] Tue, 21 May 2019 09:31 Go to previous messageGo to next message
Markus Häge is currently offline Markus HägeFriend
Messages: 54
Registered: August 2018
Member
Hi, thanks to your replies. Sometimes I'm confused with this stuff.
I got it, it works now. But another Problem occured.

I try to test the generator. The generator creates two files:

class MyDslGenerator extends AbstractGenerator {
override void doGenerate(Resource resource, IFileSystemAccess2 fsa, IGeneratorContext context) {
for(e : resource.allContents.toIterable.filter(Domainmodel)){
fsa.generateFile('File1' ,e.compile)}

for(en : resource.allContents.toIterable.filter(Domainmodel)){
fsa.generateFile('File2' ,en.compileTS)}
}

When I test it with String..assertCompilesTo(String) it throws me error: multiple files are generated.
How can i test one of this files?
Thanks,
Markus
Re: How to Test custom validation with JUnit [message #1807041 is a reply to message #1807012] Tue, 21 May 2019 16:36 Go to previous message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 13117
Registered: July 2009
Senior Member
Which assert method so you refer to?

Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/xtext/
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Previous Topic:Formatter problems
Next Topic:How to resolve terminal conflict
Goto Forum:
  


Current Time: Mon Sep 16 22:43:31 GMT 2019

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

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

Back to the top