Home Forums Business Model Unit Tests How to test a rule set in a unit test?

Viewing 3 reply threads
  • Author
    Posts
    • #10266
      Louis PaceLouis Pace
      Participant

      Consider the following three files:

      Widget.meta
      <Class>
      <Attributes>
      <Attribute name=”x” type=”string”/>
      <Attribute name=”y” type=”string” value=”(rules &quot;WidgetRules&quot;)”/>
      </Attributes>
      </Class>

      WidgetRules.ruleset
      <RuleSet>
      <Rule name=”rule”>
      <Script><![CDATA[(this’y (string-append “x = ” (this’x)))]]></Script>
      </Rule>
      </RuleSet>

      WidgetTest.utest
      <UnitTest>
      <TestCase name=”testCase”><![CDATA[(define t (Widget’new (: x “Apple”)))
      (assert-equal “x = Apple” (t’y))
      ]]></TestCase>
      </UnitTest>

      If I run the following in a scratchpad:
      (define t (Widget’new (: x “Apple”)))
      (logger ‘info (t’y))

      Then I correctly see:
      > ; 19:19:50,979 INFO [GlobalEnvironment] (NexJ Main) x = Apple

      However, the unit test fails with
      nexj.core.scripting.ScriptingError: Unknown rule set “WidgetRules”. (err.rules.unknownSet)
      at nexj.core.scripting.Intrinsic$148.invoke(Intrinsic.java:4439)
      at SysRuleSet.generate(name)$main(class:SysRuleSet.generate(name)$main:11)
      at WidgetTest.testCase(unittest:WidgetTest.testCase:2)

      I know that a reseed is required to load rulesets, but is a reseed not done at the beginning of each unit test? How does one test a rule set in a unit test?

      Thanks!

       

      0
    • #10274
      Dhruv BassiDhruv Bassi
      Moderator

      Hi Louis,

      Can you confirm what plugin version you are using for NexJ Studio?

      Also can you please right click on the unit-test on the model view and check for the options “by pass recreate, cache seed data”  ? I usually keep them un-checked for my local unit-testing during these kind of changes.

      Regards,

      Dhruv

      0
    • #10283
      Louis PaceLouis Pace
      Participant

      FYI, the plugin version is 13.2.84.000. However, the two options that you mentioned were the culprits. Disabling these allowed the unit test to run as expected.

      Thank you very much!


      Louis

       

      0
    • #10292
      Dhruv BassiDhruv Bassi
      Moderator

      Glad to hear.

      0
Viewing 3 reply threads
  • You must be logged in to reply to this topic.