Home › Forums › Business Model › Unit Tests › How to test a rule set in a unit test?
- This topic has 3 replies, 2 voices, and was last updated 5 years, 9 months ago by Community Manager.
-
AuthorPosts
-
-
February 21, 2019 at 8:21 pm #10266Louis PaceParticipant
Consider the following three files:
Widget.meta
<Class>
<Attributes>
<Attribute name=”x” type=”string”/>
<Attribute name=”y” type=”string” value=”(rules "WidgetRules")”/>
</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 = AppleHowever, 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 -
February 22, 2019 at 1:12 pm #10274Community ManagerKeymaster
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 -
February 22, 2019 at 2:14 pm #10283Louis PaceParticipant
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!
—
Louis0 -
February 22, 2019 at 3:19 pm #10292Community ManagerKeymaster
Glad to hear.
0
-
-
AuthorPosts
- You must be logged in to reply to this topic.