GraphWalker / graphwalker-project

This is the repo for the Model-based testing tool GraphWalker.

Home Page:http://graphwalker.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Can't use ReachedEdge & ReachedVertex when using TestBuilder

scophotog opened this issue · comments

I'm using MultipleModelTest.java as inspiration. I can get the EdgeCoverage and VertexCoverage to work fine.

However in the case of ReachedEdge or ReachedVertex, when using the following builder line:

new TestBuilder().addContext(at.setPathGenerator(new RandomPath(new ReachedVertex("v_confirmScreen"))), MODEL_PATH);

ReachedVertex.validate will throw a NPE because context.getModel() is null. Is there a way the model can be passed in so validate succeeds?

Are you using the latest snapshot version?

I originally tried with v3.4.2 and couldn't get it to work. I then got the source and built all the modules.

The problem is that when setting a reached stop condition, GW will validate that the specified end state exists, this fails with a NPE when the context doesn't know about the model yet, using the TestBuilder.

As a workaround until this is fixed you can set the model on the context like this

    new TestBuilder().addContext(at
      .setModel(ContextFactoryScanner.get(MODEL_PATH).create(MODEL_PATH).get(0).getModel())
      .setPathGenerator(new RandomPath(new ReachedVertex("v_confirmScreen"))), MODEL_PATH);

Thanks for the work around!

Another workaround is to set the path generator after the model is loaded like this

  @Test
  public void reachedCondition() throws IOException {
    MultipleModel_1 model_1 = new MultipleModel_1();
    MultipleModel_2 model_2 = new MultipleModel_2();
    TestBuilder builder = new TestBuilder()
      .addContext(model_1, MODEL_PATH_1)
      .addContext(model_2, MODEL_PATH_2);
    model_1.setPathGenerator(new AStarPath(new ReachedVertex("B")));
    model_2.setPathGenerator(new AStarPath(new ReachedVertex("D")));
    builder.execute();
    assertTrue(model_1.count >= 2);
    assertTrue(model_2.count >= 1);
  }

After #183 is merged you should be able to use

new TestBuilder()
  .addContext(at, MODEL_PATH, new RandomPath(new ReachedVertex("v_confirmScreen")));

or

new TestBuilder().addContext(at, MODEL_PATH, "random(reached_vertex(v_confirmScreen))");

@scophotog PR #183 is merged, can you verify that the new approach works for you and then close this issue

Will try, thanks!

I've confirmed both solutions work for me. Thanks for the quick fix!