testingmodelicaopenmodelicadymola

Any experience with annotation(TestCase(shouldFail=false))?


I'm struggling with the annotation TestCase, which seems to have appeared in Modelica language 3.5 in early 2021. Has anyone used it successfully with Dymola or OpenModelica ?

Here is a sample code I'm using to test it. The simulation fails, which should normaly be prevented by the annotation TestCase. Any suggestion to make it work on these platforms ?

model Test
  Boolean a;
equation 
  a = time < 0.5;

  assert(
    a,
    "test has failed: time is above 0.5",
    level=AssertionLevel.error);
  annotation (TestCase(shouldPass=false));
end Test;

Solution

  • For Dymola:

    So consider the following:

    package P
      model Test
        Boolean a;
      equation 
        a = time < 0.5;
    
        assert(
          a,
          "test has failed: time is above 0.5",
          level=AssertionLevel.error);
        annotation (experiment(StopTime=1), TestCase(shouldPass=false));
      end Test;
      model Test2
        annotation (TestCase(shouldPass=true));
      end Test2;
    end P;
    

    Checking P will skip Test.

    Addendum: In Dymola 2024x Refresh 1 and earlier even check with simulation will just skip them, later versions should give a summary of issues.

    A work-around for Dymola 2024x Refresh 1 is to instead use: annotation(__ModelicaAssociation(TestCase(shouldPass=false))) which was an earlier solution for the same problem.