caption: testcase created: 20230406161341763 modified: 20230406161341763 tags: Widgets title: TestCaseWidget type: text/vnd.tiddlywiki ! Introduction The testcase widget creates an independent subwiki loaded with the specified payload tiddlers and then renders a specified template from within the subwiki.The default template displays a split view with the source tiddlers on the left and the rendered tiddler titled `Output` on the right. It also displays the tiddler titled `Description` as the heading. This makes it possible to run independent tests that also serve as documentation examples. ! Content and Attributes The content of the `<$testcase>` widget is not displayed but instead is scanned for <<.wlink DataWidget>> widgets that define the payload tiddlers to be included in the test case. |!Attribute |!Description | |<<.attr template>> |Optional title of the template used to display the testcase (defaults to $:/core/ui/testcases/DefaultTemplate) | ! Payload Tiddlers The payload tiddlers are the tiddler values that are loaded into the subwiki that is created to run the tests. They are created via <<.wlink DataWidget>> widgets within the body of the `<$testcase>` widget. ! State Handling The `<$testcase>` widget sets the variable `transclusion` to a hash that reflects the names and values of all the payload tiddlers. This makes it easier for test case templates to create unique state tiddler titles using the [[qualify Macro]] or QualifyWidget. ! Test Case Conventions The following conventions are used for test case tiddlers: * `Description` contains a brief description of the test (rendered in inline mode) * `Output` contains the tiddler text to be rendered. It can also reference other tiddlers * `ExpectedResult` contains the HTML that should match the rendering of the tiddler `Output` ! Example <$testcase> <$data $tiddler="$:/core/ui/testcases/DefaultTemplate"/> <$data $tiddler="$:/core/ui/testcases/DefaultTemplate/Source"/> <$data title="Description" text="Simple example of a test case"/> <$data title="Output" text="""<$testcase> <$data title="Description" text="How to calculate 2 plus 2"/> <$data title="Output" text="<$text text={{{ =2 =[add[2]] }}}/>"/> """/>