Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » ValidatorTester - Test all Checks
ValidatorTester - Test all Checks [message #701780] Mon, 25 July 2011 15:32 Go to next message
Daniel Missing name is currently offline Daniel Missing nameFriend
Messages: 101
Registered: July 2011
Senior Member
Hi everybody.

I just wanted to start writing some unit-tests for my language. I created some testcases for the validator in code. Now I want to load all those files and send them trough the validator. Each file raises exactly one error which the validator will mention (in the Eclipse editor I see 1 error in each file).

In my unit tests I want to load those test files and let the validator run all the checks. Afterwards I want to use the assert Methods to check if the expected error (and no additional errors) are detected.

My problem is: How can I tell the ValidatorTester to perform all checks on the specified model like eclipse would do:

public class MyDslValidatorTest extends AbstractXtextTests {

  private ValidatorTester<MyDslJavaValidator> tester;

  @Override
  protected void setUp() throws Exception {
    super.setUp();
    with(MyDslStandaloneSetup.class);
    MyDslJavaValidator validator = get(MyDslJavaValidator.class);
    tester = new ValidatorTester<MyDslJavaValidator>(validator, getInjector());
  }

  public void testE00001() {
    try {
      URL url = MyDslValidatorTest.class.getResource("error/e00001.smi");
      Resource resource = getResource(url.openStream());

      Model model = (Model) resource.getContents().get(0);
      
      // ??? tester.validator().validate(model); ???
      tester.diagnose().assertErrorContains(IMessageCodes.E_00001);      
    }
    catch (Exception e) {
      fail(e.getMessage());
    }
  }


Cheers
Daniel
Re: ValidatorTester - Test all Checks [message #701896 is a reply to message #701780] Mon, 25 July 2011 18:10 Go to previous messageGo to next message
Meinte Boersma is currently offline Meinte BoersmaFriend
Messages: 434
Registered: July 2009
Location: Leiden, Netherlands
Senior Member
Just create a new Diagnostician(). Provided EMF and your correctly is correctly set up as standalone, all registered validators are bound in that Diagnostician as well. Then, you can have that object #validate(..) your model.

Re: ValidatorTester - Test all Checks [message #702257 is a reply to message #701896] Tue, 26 July 2011 06:49 Go to previous message
Daniel Missing name is currently offline Daniel Missing nameFriend
Messages: 101
Registered: July 2011
Senior Member
Thanks. I should have read the code more patientful. The ValidatorTester also provides a validate(EObject) method because it inherits from AbstractValidatorTester. As a result of this method I get an AssertableDiagnostics which allows me to perform my asserts:

private ValidatorTester<MyDslJavaValidator> tester;
...
public void testE00001() throws Exception {
    URL url = MyDslValidatorTest.class.getResource("error/e00001.dsl");
    Resource resource = getResource(url.openStream());

    Model model = (Model) resource.getContents().get(0);
    AssertableDiagnostics result = tester.validate(model);
    result.assertErrorContains(IMessageCodes.E_00001);
}


Thanks again Very Happy
Previous Topic:Extending/customizing an X-Text generated editor
Next Topic:Xtext generated parser reports errors - why?
Goto Forum:
  


Current Time: Tue Apr 16 17:36:38 GMT 2024

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

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

Back to the top