<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://community.appian.com/cfs-file/__key/system/syndication/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/"><channel><title>How to Create Expression Rule Test Cases</title><link>https://community.appian.com/success/w/guide/3342/how-to-create-expression-rule-test-cases</link><description /><dc:language>en-US</dc:language><generator>Telligent Community 12</generator><item><title>How to Create Expression Rule Test Cases</title><link>https://community.appian.com/success/w/guide/3342/how-to-create-expression-rule-test-cases</link><pubDate>Tue, 23 Apr 2024 13:23:03 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:035ef30d-5bb9-47d1-85a5-ea78a8f96c19</guid><dc:creator>Appian Max Team</dc:creator><comments>https://community.appian.com/success/w/guide/3342/how-to-create-expression-rule-test-cases#comments</comments><description>Current Revision posted to Guide by Appian Max Team on 4/23/2024 1:23:03 PM&lt;br /&gt;
&lt;div style="margin:8px 16% 8px 8%;"&gt;
&lt;p&gt;&lt;a href="https://docs.appian.com/suite/help/latest/Expression_Rules.html#test-cases"&gt;Expression rule test cases&lt;/a&gt; enable unit testing with minimal overhead by reducing the time required to test while increasing code quality. Because expression rules have a wide variety of uses, creating meaningful test cases will speed up unit, regression, and exploratory testing. Use the following guidelines to create test cases for your expression rules that will result in greater code coverage for your application. The first section provides guidelines for creating useful test cases, and the following sections explain types of expression rule test cases in greater detail with Appian examples.&lt;/p&gt;
&lt;h2 id="test_case_creation_guidelines"&gt;Test Case Creation Guidelines&lt;/h2&gt;
&lt;p&gt;The following guidelines apply to expression rules which output a value:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Create test cases from the start of application development to aid regression testing.&amp;nbsp;&lt;/li&gt;
&lt;li&gt;If an expression rule calls another expression rule, do not duplicate test cases already created in the child within the parent rule. The parent rule should contain test cases that test any logic within the parent rule itself and should assume the child has sufficient test cases.&lt;/li&gt;
&lt;li&gt;When possible, break down large expressions to individual rules so that it is easier to ensure test coverage with expression rule test cases&lt;/li&gt;
&lt;li&gt;When expression rule test cases are evaluated, the expression is evaluated first, followed by the assertion within the test case. Avoid the use of now() in test case assertions, as this can trigger false negatives due to the dateTime type evaluating the values down to the millisecond. Instead, check whether the field is not blank.&lt;/li&gt;
&lt;li&gt;Use test!output to assert the output equals what you would expect.&lt;/li&gt;
&lt;li&gt;Use &lt;a href="/w/guide/3339/exploratory-testing"&gt;Exploratory Testing&lt;/a&gt; to identify edge cases for which to create test cases.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id="types_of_test_cases"&gt;Types of Test Cases&lt;/h2&gt;
&lt;p&gt;When creating test cases, consider the two types of test cases: &lt;b&gt;coverage tests&lt;/b&gt; and &lt;b&gt;error handling&lt;/b&gt; tests. Every expression rule should always have at least one of each kind of test case.&lt;/p&gt;
&lt;table&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;p&gt;&lt;b&gt;Test Type&lt;/b&gt;&lt;/p&gt;
&lt;/td&gt;
&lt;td&gt;
&lt;p&gt;&lt;b&gt;Description&lt;/b&gt;&lt;/p&gt;
&lt;/td&gt;
&lt;td&gt;
&lt;p&gt;&lt;b&gt;Implementation&lt;/b&gt;&lt;/p&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;p&gt;Coverage&lt;/p&gt;
&lt;/td&gt;
&lt;td&gt;
&lt;p&gt;A coverage test ensures the rule inputs result in the intended output. In other words, an area of the rule has been sufficiently &amp;ldquo;covered&amp;rdquo; via a test case.&lt;/p&gt;
&lt;/td&gt;
&lt;td&gt;
&lt;p&gt;Set inputs to expected values.&amp;nbsp;&lt;/p&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;p&gt;Error Handling&lt;/p&gt;
&lt;/td&gt;
&lt;td&gt;
&lt;p&gt;An error handling test ensures the expression rule has proper error handling.&lt;/p&gt;
&lt;/td&gt;
&lt;td&gt;
&lt;p&gt;Set inputs to values that would typically break the rule.&lt;/p&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;h2 id="creating_coverage_tests"&gt;Creating Coverage Tests&lt;/h2&gt;
&lt;h3&gt;Use the diagram below to determine which test cases are required and how to set assertions.&lt;/h3&gt;
&lt;div style="margin-bottom:3rem;margin-top:3rem;"&gt;&lt;img style="box-shadow:3px 3px 5px rgba(0, 0, 0, 0.1);" alt=" " src="/resized-image/__size/640x480/__key/communityserver-wikis-components-files/00-00-00-00-46/expressionRuleFlow.jpg" /&gt;&lt;/div&gt;
&lt;h3 id="coverage_test_case_examples"&gt;Coverage Test Case Examples&lt;/h3&gt;
&lt;h3&gt;Limited Number of Outcomes&lt;/h3&gt;
&lt;p&gt;If your expression rule has a limited number of outcomes, use the below examples to guide your test case creation. Use test!output to assert that the output is equal to the value you expect. Each outcome should have a test case and corresponding assertion.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;b&gt;Nested if()s&lt;/b&gt;: Create 1 test case per possible condition&lt;/li&gt;
&lt;li&gt;&lt;b&gt;Choose()&lt;/b&gt;: Create 1 test case per key&lt;/li&gt;
&lt;li&gt;&lt;b&gt;Mathematical Comparisons&lt;/b&gt;: Create 1 test case per possible comparison&amp;nbsp;
&lt;ul&gt;
&lt;li&gt;For example, for a &lt;i&gt;greater than&lt;/i&gt; comparison, you must have 3 cases covering when the input is less than, equal to, or greater than the comparative value&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;Unlimited Number of Outcomes&lt;/h3&gt;
&lt;p&gt;If your expression rule has an unlimited number of outcomes, use the below examples to guide your test case creation. Use test!output where it makes sense to ensure the output is equal to the expected value.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;b&gt;Calculations&lt;/b&gt;: Based on the calculation being run, identify inputs that will cover groupings of possible outcomes. The asserted output should be calculated outside of Appian and then asserted within the case.
&lt;ul&gt;
&lt;li&gt;For example, if you have a rule that is executing the following calculation: &lt;i&gt;A-B&lt;/i&gt;, with integers &lt;i&gt;A&lt;/i&gt; and &lt;i&gt;B&lt;/i&gt;, test cases should cover the following scenarios as they all would reveal something different about the calculation:
&lt;ul&gt;
&lt;li&gt;A&amp;gt;B (output is positive)&lt;/li&gt;
&lt;li&gt;A&amp;lt;B (output is negative)&lt;/li&gt;
&lt;li&gt;A=B (output is 0)&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;ul&gt;
&lt;li&gt;&lt;b&gt;Integrations: Expression Rule Test Cases can be used to test integration connectivity prior to a deployment. Create an expression rule that calls the integration and a test case that passes in data to populate the request. Set the assertion to &amp;ldquo;expression evaluates to true&amp;rdquo;. The expression should check that the &amp;ldquo;success&amp;rdquo; output of the integration = true. Add these expression rules to an app that is deployed prior to your business application.&lt;/b&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Date Times&lt;/strong&gt;:&amp;nbsp;Create test cases which cover all groupings of expected outcomes, including all known edge cases. Assert that the output is correct for each test case.&amp;nbsp;
&lt;ul&gt;
&lt;li&gt;For example, if a rule checks whether a date is a work day (calisworkday(datetime)), create test cases with the following inputs to test the possible outcomes. Use the value in parenthesis to assert that test!output is the correct value:
&lt;ul&gt;
&lt;li&gt;A work day (true)&lt;/li&gt;
&lt;li&gt;A weekend day (false)&lt;/li&gt;
&lt;li&gt;A holiday (false)&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;ul&gt;
&lt;li&gt;Consider test cases that go &amp;ldquo;stale&amp;rdquo; (rules where the output depends on whether inputs are in the past, future, etc). Avoid using hard coded dates and instead, use the appropriate Appian date and time functions (now(), today(), etc.) to ensure that test inputs will last for the lifetime of the application. As mentioned previously, do not use now() in test case assertions.&lt;/li&gt;
&lt;li&gt;If the rule contains calculations on dates in particular timezones, use the gmt() and local() functions to enforce a timezone and assert the correct output for that timezone.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;b&gt;Type Constructors&lt;/b&gt;:&amp;nbsp;Test cases are only necessary to test any logic within the rule that is outside of the constructor itself. &amp;ldquo;Assertion expression evaluates to true&amp;rdquo; is typically useful for these types of test cases.
&lt;ul&gt;
&lt;li&gt;If the rule takes a raw set of data and only casts items that meet specific criteria, a test case can be created in which you validate that all items in the output meet that criteria.&lt;/li&gt;
&lt;li&gt;If the rule casts individual fields from a rule input to a new data type, create a test case that asserts that each field equals what is expected by using test!output.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id="creating_error_handling_tests"&gt;Creating Error Handling Tests&lt;/h2&gt;
&lt;p&gt;Error handling test cases should be created based on the functions and inputs of the rule. &lt;b&gt;All &lt;/b&gt;rules should have null handling test cases (unless already covered by a parent rule), while other error handling scenarios should be determined at the Designer&amp;rsquo;s discretion. All error handling cases should have the test output match an asserted output.&lt;/p&gt;
&lt;h3 id="error_handling_test_case_examples"&gt;Error Handling Test Case Examples&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;&lt;b&gt;Null Handling: Set one, some, or all rule inputs to null to ensure the rule executes properly and outputs an expected value. In many cases, more than one null handling test case may be necessary.&lt;/b&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;div style="margin-bottom:3rem;margin-top:3rem;"&gt;&lt;img style="box-shadow:3px 3px 5px rgba(0, 0, 0, 0.1);" alt=" " src="/resized-image/__size/960x720/__key/communityserver-wikis-components-files/00-00-00-00-46/expressionImage1.png" /&gt;&lt;/div&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Invalid Mathematical Expressions&lt;/strong&gt;: In rules that execute a calculation, provide inputs that produce an invalid calculation, such as a denominator of zero. Ensure the rule still executes properly and outputs the expected value.
&lt;ul&gt;
&lt;li&gt;For example, if your rule is calculating the square root of the difference between &lt;i&gt;A &lt;/i&gt;and &lt;i&gt;B&lt;/i&gt;, create a case in which B &amp;gt; A.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;ul&gt;
&lt;li&gt;&lt;b&gt;Functions that error given invalid inputs: If a rule uses functions that produce an expression error if the input is invalid (e.g. user/group functions, not(), etc), create a test case for each invalid input to verify that expression errors are avoided.&lt;/b&gt;
&lt;ul&gt;
&lt;li&gt;For example, if your rule has a username input, cases should be created in which a random non-username string is passed in. The rule should be coded to handle this case properly.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Date Times&lt;/strong&gt;: Create test cases with datetimes outside of what the rule expects to ensure that the rule handles them appropriately.&lt;/li&gt;
&lt;/ul&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Queries&lt;/strong&gt;:&amp;nbsp;
&lt;ul&gt;
&lt;li&gt;For queries in which data is consistent across environments, regardless of user interaction with the system (i.e. reference data), create test cases with data that will always be returned and assert that the test output matches the desired value.&lt;/li&gt;
&lt;li&gt;For queries on transactional data, expression rule test cases should not be used to validate that a particular data set is returned because data can vary based on the environment and user interaction. However, test cases can still be used in the following ways:
&lt;ul&gt;
&lt;li&gt;On all expression rules that have queries, you can create a test case which asserts that the &amp;ldquo;&lt;a href="https://docs.appian.com/suite/help/20.3/Expression_Rules.html#test-case-assertions"&gt;Test completes without errors&lt;/a&gt;&amp;rdquo; to validate &lt;b&gt;database connectivity&lt;/b&gt;.&amp;nbsp;&lt;/li&gt;
&lt;li&gt;If the query ignores null filter values, include a test case which passes in values for all possible filters and asserts that the test completes without errors to ensure that all&lt;b&gt; field names and filter configurations&lt;/b&gt; are valid.&lt;/li&gt;
&lt;li&gt;If the query does not ignore null filter values, create &lt;b&gt;null-handling&lt;/b&gt; test cases for the rule.&amp;nbsp;&lt;/li&gt;
&lt;li&gt;For all filters that are created, test cases can be used to validate that the returned results match the&lt;b&gt; filter value&lt;/b&gt; that was passed in. For example, if &amp;ldquo;true&amp;rdquo; is passed into an &amp;ldquo;isActive&amp;rdquo; filter in the query, a test case can validate that all results returned have isActive=true. For test cases like these, include appropriate null handling for when no data matches the filter criteria.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Use test cases to assert that the output is of the same &lt;b&gt;data type&lt;/b&gt; as the data entity being queried. This can be done using the &amp;ldquo;&lt;a href="https://docs.appian.com/suite/help/20.3/Expression_Rules.html#test-case-assertions"&gt;Assertion expression evaluates to true&lt;/a&gt;&amp;rdquo; assertion option, where the expression would check that the type of test!output matches the expected type using the typeof() function.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;i&gt;Note: Expression rules containing queries should only include the a!queryEntity() function. Any expressions to manipulate the data or output different values based on the query results should be done in separate expression rules, using the results of the query as a rule input. This allows flexibility to assert that the manipulation or conditional output operates correctly without relying on transaction data that can change across Appian environments.&lt;/i&gt;&lt;/p&gt;
&lt;h2 id="example_expression_rule"&gt;Example Expression Rule&lt;/h2&gt;
&lt;h4&gt;An example expression rule that has coverage tests and error handling tests can be found below.&lt;/h4&gt;
&lt;div style="margin-bottom:3rem;margin-top:3rem;"&gt;&lt;img style="box-shadow:3px 3px 5px rgba(0, 0, 0, 0.1);" alt=" " src="/resized-image/__size/960x720/__key/communityserver-wikis-components-files/00-00-00-00-46/expressionImage2.png" /&gt;&lt;/div&gt;
&lt;div style="margin-bottom:3rem;margin-top:3rem;"&gt;&lt;img style="box-shadow:3px 3px 5px rgba(0, 0, 0, 0.1);" alt=" " src="/resized-image/__size/960x720/__key/communityserver-wikis-components-files/00-00-00-00-46/expressionImage3.png" /&gt;&lt;/div&gt;
&lt;p&gt;&lt;b&gt;Figure &lt;/b&gt;&lt;b&gt;&lt;i&gt;N&amp;nbsp;&lt;/i&gt;&lt;/b&gt;&lt;b&gt;: Sample Expression Rule&lt;/b&gt;&lt;/p&gt;
&lt;div style="margin-bottom:3rem;margin-top:3rem;"&gt;&lt;img style="box-shadow:3px 3px 5px rgba(0, 0, 0, 0.1);" alt=" " src="/resized-image/__size/960x720/__key/communityserver-wikis-components-files/00-00-00-00-46/expressionImage4.png" /&gt;&lt;/div&gt;
&lt;p&gt;&lt;b&gt;Figure &lt;/b&gt;&lt;b&gt;&lt;i&gt;M&amp;nbsp;&lt;/i&gt;&lt;/b&gt;&lt;b&gt;: Sample Test Cases&lt;/b&gt;&lt;/p&gt;
&lt;p&gt;These are test cases a user could have set up for the rule provided in &lt;b&gt;&lt;i&gt;Figure N&lt;/i&gt;&lt;/b&gt;. The first box contains &lt;b&gt;Coverage Tests&lt;/b&gt;. They provide code coverage by testing with expected inputs and outputs. The second box contains &lt;b&gt;Error Handling Tests&lt;/b&gt;. These tests are staged with inputs that would typically result in a denominator of 0. Finally, the third box contains &lt;b&gt;Null Handling Tests&lt;/b&gt;. This is another specific type of error handling tests. They are used to verify that our rule can properly handle null inputs. Note that more than one was required for this rule.&lt;/p&gt;
&lt;h2 id="regression_testing_with_test_cases"&gt;Regression Testing with Test Cases&lt;/h2&gt;
&lt;p&gt;Test cases make it easier and faster to regression test. Before making a change to an existing expression rule, run all existing test cases within the rule and resolve any that have failed. After making the change, add coverage and error handling test cases to test the change. Finally, run all test cases to ensure the update didn&amp;rsquo;t break any existing cases.&lt;/p&gt;
&lt;p&gt;Before a deployment, run the Automated Rules Testing Application (ART) in the target environment (non-production) to ensure all test cases work as expected before the deployment. If any rules do not work, resolve the issues in the lower environment prior to the deployment. After the deployment, re-run ART in the target environment to ensure all new and old test cases work as expected.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Note: These examples are not all-encompassing. Best judgement should be used to determine what cases are required.&lt;/p&gt;
&lt;/div&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;

&lt;div style="font-size: 90%;"&gt;Tags: testing, Architecture&lt;/div&gt;
</description></item><item><title>How to Create Expression Rule Test Cases</title><link>https://community.appian.com/success/w/guide/3342/how-to-create-expression-rule-test-cases/revision/13</link><pubDate>Thu, 11 Jan 2024 15:13:04 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:035ef30d-5bb9-47d1-85a5-ea78a8f96c19</guid><dc:creator>joel.larin</dc:creator><comments>https://community.appian.com/success/w/guide/3342/how-to-create-expression-rule-test-cases#comments</comments><description>Revision 13 posted to Guide by joel.larin on 1/11/2024 3:13:04 PM&lt;br /&gt;
&lt;div style="margin:8px 16% 8px 8%;"&gt;
&lt;p&gt;&lt;a href="https://docs.appian.com/suite/help/latest/Expression_Rules.html#test-cases"&gt;Expression rule test cases&lt;/a&gt; enable unit testing with minimal overhead by reducing the time required to test while increasing code quality. Because expression rules have a wide variety of uses, creating meaningful test cases will speed up unit, regression, and exploratory testing. Use the following guidelines to create test cases for your expression rules that will result in greater code coverage for your application. The first section provides guidelines for creating useful test cases, and the following sections explain types of expression rule test cases in greater detail with Appian examples.&lt;/p&gt;
&lt;h2 id="test_case_creation_guidelines"&gt;Test Case Creation Guidelines&lt;/h2&gt;
&lt;p&gt;The following guidelines apply to expression rules which output a value:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Create test cases from the start of application development to aid regression testing.&amp;nbsp;&lt;/li&gt;
&lt;li&gt;If an expression rule calls another expression rule, do not duplicate test cases already created in the child within the parent rule. The parent rule should contain test cases that test any logic within the parent rule itself and should assume the child has sufficient test cases.&lt;/li&gt;
&lt;li&gt;When possible, break down large expressions to individual rules so that it is easier to ensure test coverage with expression rule test cases&lt;/li&gt;
&lt;li&gt;When expression rule test cases are evaluated, the expression is evaluated first, followed by the assertion within the test case. Avoid the use of now() in test case assertions, as this can trigger false negatives due to the dateTime type evaluating the values down to the millisecond. Instead, check whether the field is not blank.&lt;/li&gt;
&lt;li&gt;Use test!output to assert the output equals what you would expect.&lt;/li&gt;
&lt;li&gt;Use &lt;a href="/w/guide/3339/exploratory-testing"&gt;Exploratory Testing&lt;/a&gt; to identify edge cases for which to create test cases.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id="types_of_test_cases"&gt;Types of Test Cases&lt;/h2&gt;
&lt;p&gt;When creating test cases, consider the two types of test cases: &lt;b&gt;coverage tests&lt;/b&gt; and &lt;b&gt;error handling&lt;/b&gt; tests. Every expression rule should always have at least one of each kind of test case.&lt;/p&gt;
&lt;table&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;p&gt;&lt;b&gt;Test Type&lt;/b&gt;&lt;/p&gt;
&lt;/td&gt;
&lt;td&gt;
&lt;p&gt;&lt;b&gt;Description&lt;/b&gt;&lt;/p&gt;
&lt;/td&gt;
&lt;td&gt;
&lt;p&gt;&lt;b&gt;Implementation&lt;/b&gt;&lt;/p&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;p&gt;Coverage&lt;/p&gt;
&lt;/td&gt;
&lt;td&gt;
&lt;p&gt;A coverage test ensures the rule inputs result in the intended output. In other words, an area of the rule has been sufficiently &amp;ldquo;covered&amp;rdquo; via a test case.&lt;/p&gt;
&lt;/td&gt;
&lt;td&gt;
&lt;p&gt;Set inputs to expected values.&amp;nbsp;&lt;/p&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;p&gt;Error Handling&lt;/p&gt;
&lt;/td&gt;
&lt;td&gt;
&lt;p&gt;An error handling test ensures the expression rule has proper error handling.&lt;/p&gt;
&lt;/td&gt;
&lt;td&gt;
&lt;p&gt;Set inputs to values that would typically break the rule.&lt;/p&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;h2 id="creating_coverage_tests"&gt;Creating Coverage Tests&lt;/h2&gt;
&lt;h3&gt;Use the diagram below to determine which test cases are required and how to set assertions.&lt;/h3&gt;
&lt;div style="margin-bottom:3rem;margin-top:3rem;"&gt;&lt;img style="box-shadow:3px 3px 5px rgba(0, 0, 0, 0.1);" alt=" " src="/resized-image/__size/640x480/__key/communityserver-wikis-components-files/00-00-00-00-46/expressionRuleFlow.jpg" /&gt;&lt;/div&gt;
&lt;h3 id="coverage_test_case_examples"&gt;Coverage Test Case Examples&lt;/h3&gt;
&lt;h3&gt;Limited Number of Outcomes&lt;/h3&gt;
&lt;p&gt;If your expression rule has a limited number of outcomes, use the below examples to guide your test case creation. Use test!output to assert that the output is equal to the value you expect. Each outcome should have a test case and corresponding assertion.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;b&gt;Nested if()s&lt;/b&gt;: Create 1 test case per possible condition&lt;/li&gt;
&lt;li&gt;&lt;b&gt;Choose()&lt;/b&gt;: Create 1 test case per key&lt;/li&gt;
&lt;li&gt;&lt;b&gt;Mathematical Comparisons&lt;/b&gt;: Create 1 test case per possible comparison&amp;nbsp;
&lt;ul&gt;
&lt;li&gt;For example, for a &lt;i&gt;greater than&lt;/i&gt; comparison, you must have 3 cases covering when the input is less than, equal to, or greater than the comparative value&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;Unlimited Number of Outcomes&lt;/h3&gt;
&lt;p&gt;If your expression rule has an unlimited number of outcomes, use the below examples to guide your test case creation. Use test!output where it makes sense to ensure the output is equal to the expected value.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;b&gt;Calculations&lt;/b&gt;: Based on the calculation being run, identify inputs that will cover groupings of possible outcomes. The asserted output should be calculated outside of Appian and then asserted within the case.
&lt;ul&gt;
&lt;li&gt;For example, if you have a rule that is executing the following calculation: &lt;i&gt;A-B&lt;/i&gt;, with integers &lt;i&gt;A&lt;/i&gt; and &lt;i&gt;B&lt;/i&gt;, test cases should cover the following scenarios as they all would reveal something different about the calculation:
&lt;ul&gt;
&lt;li&gt;A&amp;gt;B (output is positive)&lt;/li&gt;
&lt;li&gt;A&amp;lt;B (output is negative)&lt;/li&gt;
&lt;li&gt;A=B (output is 0)&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;ul&gt;
&lt;li&gt;&lt;b&gt;Integrations: Expression Rule Test Cases can be used to test integration connectivity prior to a deployment. Create an expression rule that calls the integration and a test case that passes in data to populate the request. Set the assertion to &amp;ldquo;expression evaluates to true&amp;rdquo;. The expression should check that the &amp;ldquo;success&amp;rdquo; output of the integration = true. Add these expression rules to an app that is deployed prior to your business application.&lt;/b&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Date Times&lt;/strong&gt;:&amp;nbsp;Create test cases which cover all groupings of expected outcomes, including all known edge cases. Assert that the output is correct for each test case.&amp;nbsp;
&lt;ul&gt;
&lt;li&gt;For example, if a rule checks whether a date is a work day (calisworkday(datetime)), create test cases with the following inputs to test the possible outcomes. Use the value in parenthesis to assert that test!output is the correct value:
&lt;ul&gt;
&lt;li&gt;A work day (true)&lt;/li&gt;
&lt;li&gt;A weekend day (false)&lt;/li&gt;
&lt;li&gt;A holiday (false)&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;ul&gt;
&lt;li&gt;Consider test cases that go &amp;ldquo;stale&amp;rdquo; (rules where the output depends on whether inputs are in the past, future, etc). Avoid using hard coded dates and instead, use the appropriate Appian date and time functions (now(), today(), etc.) to ensure that test inputs will last for the lifetime of the application. As mentioned previously, do not use now() in test case assertions.&lt;/li&gt;
&lt;li&gt;If the rule contains calculations on dates in particular timezones, use the gmt() and local() functions to enforce a timezone and assert the correct output for that timezone.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;b&gt;Type Constructors&lt;/b&gt;:&amp;nbsp;Test cases are only necessary to test any logic within the rule that is outside of the constructor itself. &amp;ldquo;Assertion expression evaluates to true&amp;rdquo; is typically useful for these types of test cases.
&lt;ul&gt;
&lt;li&gt;If the rule takes a raw set of data and only casts items that meet specific criteria, a test case can be created in which you validate that all items in the output meet that criteria.&lt;/li&gt;
&lt;li&gt;If the rule casts individual fields from a rule input to a new data type, create a test case that asserts that each field equals what is expected by using test!output.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id="creating_error_handling_tests"&gt;Creating Error Handling Tests&lt;/h2&gt;
&lt;p&gt;Error handling test cases should be created based on the functions and inputs of the rule. &lt;b&gt;All &lt;/b&gt;rules should have null handling test cases (unless already covered by a parent rule), while other error handling scenarios should be determined at the Designer&amp;rsquo;s discretion. All error handling cases should have the test output match an asserted output.&lt;/p&gt;
&lt;h3 id="error_handling_test_case_examples"&gt;Error Handling Test Case Examples&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;&lt;b&gt;Null Handling: Set one, some, or all rule inputs to null to ensure the rule executes properly and outputs an expected value. In many cases, more than one null handling test case may be necessary.&lt;/b&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;div style="margin-bottom:3rem;margin-top:3rem;"&gt;&lt;img style="box-shadow:3px 3px 5px rgba(0, 0, 0, 0.1);" alt=" " src="/resized-image/__size/960x720/__key/communityserver-wikis-components-files/00-00-00-00-46/expressionImage1.png" /&gt;&lt;/div&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Invalid Mathematical Expressions&lt;/strong&gt;: In rules that execute a calculation, provide inputs that produce an invalid calculation, such as a denominator of zero. Ensure the rule still executes properly and outputs the expected value.
&lt;ul&gt;
&lt;li&gt;For example, if your rule is calculating the square root of the difference between &lt;i&gt;A &lt;/i&gt;and &lt;i&gt;B&lt;/i&gt;, create a case in which B &amp;gt; A.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;ul&gt;
&lt;li&gt;&lt;b&gt;Functions that error given invalid inputs: If a rule uses functions that produce an expression error if the input is invalid (e.g. user/group functions, not(), etc), create a test case for each invalid input to verify that expression errors are avoided.&lt;/b&gt;
&lt;ul&gt;
&lt;li&gt;For example, if your rule has a username input, cases should be created in which a random non-username string is passed in. The rule should be coded to handle this case properly.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Date Times&lt;/strong&gt;: Create test cases with datetimes outside of what the rule expects to ensure that the rule handles them appropriately.&lt;/li&gt;
&lt;/ul&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Queries&lt;/strong&gt;:&amp;nbsp;
&lt;ul&gt;
&lt;li&gt;For queries in which data is consistent across environments, regardless of user interaction with the system (i.e. reference data), create test cases with data that will always be returned and assert that the test output matches the desired value.&lt;/li&gt;
&lt;li&gt;For queries on transactional data, expression rule test cases should not be used to validate that a particular data set is returned because data can vary based on the environment and user interaction. However, test cases can still be used in the following ways:
&lt;ul&gt;
&lt;li&gt;On all expression rules that have queries, you can create a test case which asserts that the &amp;ldquo;&lt;a href="https://docs.appian.com/suite/help/20.3/Expression_Rules.html#test-case-assertions"&gt;Test completes without errors&lt;/a&gt;&amp;rdquo; to validate &lt;b&gt;database connectivity&lt;/b&gt;.&amp;nbsp;&lt;/li&gt;
&lt;li&gt;If the query ignores null filter values, include a test case which passes in values for all possible filters and asserts that the test completes without errors to ensure that all&lt;b&gt; field names and filter configurations&lt;/b&gt; are valid.&lt;/li&gt;
&lt;li&gt;If the query does not ignore null filter values, create &lt;b&gt;null-handling&lt;/b&gt; test cases for the rule.&amp;nbsp;&lt;/li&gt;
&lt;li&gt;For all filters that are created, test cases can be used to validate that the returned results match the&lt;b&gt; filter value&lt;/b&gt; that was passed in. For example, if &amp;ldquo;true&amp;rdquo; is passed into an &amp;ldquo;isActive&amp;rdquo; filter in the query, a test case can validate that all results returned have isActive=true. For test cases like these, include appropriate null handling for when no data matches the filter criteria.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Use test cases to assert that the output is of the same &lt;b&gt;data type&lt;/b&gt; as the data entity being queried. This can be done using the &amp;ldquo;&lt;a href="https://docs.appian.com/suite/help/20.3/Expression_Rules.html#test-case-assertions"&gt;Assertion expression evaluates to true&lt;/a&gt;&amp;rdquo; assertion option, where the expression would check that the type of test!output matches the expected type using the typeof() function.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;i&gt;Note: Expression rules containing queries should only include the a!queryEntity() function. Any expressions to manipulate the data or output different values based on the query results should be done in separate expression rules, using the results of the query as a rule input. This allows flexibility to assert that the manipulation or conditional output operates correctly without relying on transaction data that can change across Appian environments.&lt;/i&gt;&lt;/p&gt;
&lt;h2 id="example_expression_rule"&gt;Example Expression Rule&lt;/h2&gt;
&lt;h4&gt;An example expression rule that has coverage tests and error handling tests can be found below.&lt;/h4&gt;
&lt;div style="margin-bottom:3rem;margin-top:3rem;"&gt;&lt;img style="box-shadow:3px 3px 5px rgba(0, 0, 0, 0.1);" alt=" " src="/resized-image/__size/960x720/__key/communityserver-wikis-components-files/00-00-00-00-46/expressionImage2.png" /&gt;&lt;/div&gt;
&lt;div style="margin-bottom:3rem;margin-top:3rem;"&gt;&lt;img style="box-shadow:3px 3px 5px rgba(0, 0, 0, 0.1);" alt=" " src="/resized-image/__size/960x720/__key/communityserver-wikis-components-files/00-00-00-00-46/expressionImage3.png" /&gt;&lt;/div&gt;
&lt;p&gt;&lt;b&gt;Figure &lt;/b&gt;&lt;b&gt;&lt;i&gt;N&amp;nbsp;&lt;/i&gt;&lt;/b&gt;&lt;b&gt;: Sample Expression Rule&lt;/b&gt;&lt;/p&gt;
&lt;div style="margin-bottom:3rem;margin-top:3rem;"&gt;&lt;img style="box-shadow:3px 3px 5px rgba(0, 0, 0, 0.1);" alt=" " src="/resized-image/__size/960x720/__key/communityserver-wikis-components-files/00-00-00-00-46/expressionImage4.png" /&gt;&lt;/div&gt;
&lt;p&gt;&lt;b&gt;Figure &lt;/b&gt;&lt;b&gt;&lt;i&gt;M&amp;nbsp;&lt;/i&gt;&lt;/b&gt;&lt;b&gt;: Sample Test Cases&lt;/b&gt;&lt;/p&gt;
&lt;p&gt;These are test cases a user could have set up for the rule provided in &lt;b&gt;&lt;i&gt;Figure N&lt;/i&gt;&lt;/b&gt;. The first box contains &lt;b&gt;Coverage Tests&lt;/b&gt;. They provide code coverage by testing with expected inputs and outputs. The second box contains &lt;b&gt;Error Handling Tests&lt;/b&gt;. These tests are staged with inputs that would typically result in a denominator of 0. Finally, the third box contains &lt;b&gt;Null Handling Tests&lt;/b&gt;. This is another specific type of error handling tests. They are used to verify that our rule can properly handle null inputs. Note that more than one was required for this rule.&lt;/p&gt;
&lt;h2 id="regression_testing_with_test_cases"&gt;Regression Testing with Test Cases&lt;/h2&gt;
&lt;p&gt;Test cases make it easier and faster to regression test. Before making a change to an existing expression rule, run all existing test cases within the rule and resolve any that have failed. After making the change, add coverage and error handling test cases to test the change. Finally, run all test cases to ensure the update didn&amp;rsquo;t break any existing cases.&lt;/p&gt;
&lt;p&gt;Before a deployment, run the Automated Rules Testing Application (ART) in the target environment (non-production) to ensure all test cases work as expected before the deployment. If any rules do not work, resolve the issues in the lower environment prior to the deployment. After the deployment, re-run ART in the target environment to ensure all new and old test cases work as expected.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Note: These examples are not all-encompassing. Best judgement should be used to determine what cases are required.&lt;/p&gt;
&lt;/div&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;

&lt;div style="font-size: 90%;"&gt;Tags: testing, Architecture&lt;/div&gt;
</description></item><item><title>How to Create Expression Rule Test Cases</title><link>https://community.appian.com/success/w/guide/3342/how-to-create-expression-rule-test-cases/revision/12</link><pubDate>Thu, 11 Jan 2024 15:08:52 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:035ef30d-5bb9-47d1-85a5-ea78a8f96c19</guid><dc:creator>joel.larin</dc:creator><comments>https://community.appian.com/success/w/guide/3342/how-to-create-expression-rule-test-cases#comments</comments><description>Revision 12 posted to Guide by joel.larin on 1/11/2024 3:08:52 PM&lt;br /&gt;
&lt;div style="margin:8px 16% 8px 8%;"&gt;
&lt;p&gt;&lt;a href="https://docs.appian.com/suite/help/latest/Expression_Rules.html#test-cases"&gt;Expression rule test cases&lt;/a&gt; enable unit testing with minimal overhead by reducing the time required to test while increasing code quality. Because expression rules have a wide variety of uses, creating meaningful test cases will speed up unit, regression, and exploratory testing. Use the following guidelines to create test cases for your expression rules that will result in greater code coverage for your application. The first section provides guidelines for creating useful test cases, and the following sections explain types of expression rule test cases in greater detail with Appian examples.&lt;/p&gt;
&lt;div style="margin-top:22px;width:90%;"&gt;&lt;a href="https://youtu.be/ATqelb2CJj4?feature=shared"&gt;youtu.be/ATqelb2CJj4&lt;/a&gt;&lt;/div&gt;
&lt;h2 id="test_case_creation_guidelines"&gt;Test Case Creation Guidelines&lt;/h2&gt;
&lt;p&gt;The following guidelines apply to expression rules which output a value:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Create test cases from the start of application development to aid regression testing.&amp;nbsp;&lt;/li&gt;
&lt;li&gt;If an expression rule calls another expression rule, do not duplicate test cases already created in the child within the parent rule. The parent rule should contain test cases that test any logic within the parent rule itself and should assume the child has sufficient test cases.&lt;/li&gt;
&lt;li&gt;When possible, break down large expressions to individual rules so that it is easier to ensure test coverage with expression rule test cases&lt;/li&gt;
&lt;li&gt;When expression rule test cases are evaluated, the expression is evaluated first, followed by the assertion within the test case. Avoid the use of now() in test case assertions, as this can trigger false negatives due to the dateTime type evaluating the values down to the millisecond. Instead, check whether the field is not blank.&lt;/li&gt;
&lt;li&gt;Use test!output to assert the output equals what you would expect.&lt;/li&gt;
&lt;li&gt;Use &lt;a href="/w/guide/3339/exploratory-testing"&gt;Exploratory Testing&lt;/a&gt; to identify edge cases for which to create test cases.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id="types_of_test_cases"&gt;Types of Test Cases&lt;/h2&gt;
&lt;p&gt;When creating test cases, consider the two types of test cases: &lt;b&gt;coverage tests&lt;/b&gt; and &lt;b&gt;error handling&lt;/b&gt; tests. Every expression rule should always have at least one of each kind of test case.&lt;/p&gt;
&lt;table&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;p&gt;&lt;b&gt;Test Type&lt;/b&gt;&lt;/p&gt;
&lt;/td&gt;
&lt;td&gt;
&lt;p&gt;&lt;b&gt;Description&lt;/b&gt;&lt;/p&gt;
&lt;/td&gt;
&lt;td&gt;
&lt;p&gt;&lt;b&gt;Implementation&lt;/b&gt;&lt;/p&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;p&gt;Coverage&lt;/p&gt;
&lt;/td&gt;
&lt;td&gt;
&lt;p&gt;A coverage test ensures the rule inputs result in the intended output. In other words, an area of the rule has been sufficiently &amp;ldquo;covered&amp;rdquo; via a test case.&lt;/p&gt;
&lt;/td&gt;
&lt;td&gt;
&lt;p&gt;Set inputs to expected values.&amp;nbsp;&lt;/p&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;p&gt;Error Handling&lt;/p&gt;
&lt;/td&gt;
&lt;td&gt;
&lt;p&gt;An error handling test ensures the expression rule has proper error handling.&lt;/p&gt;
&lt;/td&gt;
&lt;td&gt;
&lt;p&gt;Set inputs to values that would typically break the rule.&lt;/p&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;h2 id="creating_coverage_tests"&gt;Creating Coverage Tests&lt;/h2&gt;
&lt;h3&gt;Use the diagram below to determine which test cases are required and how to set assertions.&lt;/h3&gt;
&lt;div style="margin-bottom:3rem;margin-top:3rem;"&gt;&lt;img style="box-shadow:3px 3px 5px rgba(0, 0, 0, 0.1);" alt=" " src="/resized-image/__size/640x480/__key/communityserver-wikis-components-files/00-00-00-00-46/expressionRuleFlow.jpg" /&gt;&lt;/div&gt;
&lt;h3 id="coverage_test_case_examples"&gt;Coverage Test Case Examples&lt;/h3&gt;
&lt;h3&gt;Limited Number of Outcomes&lt;/h3&gt;
&lt;p&gt;If your expression rule has a limited number of outcomes, use the below examples to guide your test case creation. Use test!output to assert that the output is equal to the value you expect. Each outcome should have a test case and corresponding assertion.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;b&gt;Nested if()s&lt;/b&gt;: Create 1 test case per possible condition&lt;/li&gt;
&lt;li&gt;&lt;b&gt;Choose()&lt;/b&gt;: Create 1 test case per key&lt;/li&gt;
&lt;li&gt;&lt;b&gt;Mathematical Comparisons&lt;/b&gt;: Create 1 test case per possible comparison&amp;nbsp;
&lt;ul&gt;
&lt;li&gt;For example, for a &lt;i&gt;greater than&lt;/i&gt; comparison, you must have 3 cases covering when the input is less than, equal to, or greater than the comparative value&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;Unlimited Number of Outcomes&lt;/h3&gt;
&lt;p&gt;If your expression rule has an unlimited number of outcomes, use the below examples to guide your test case creation. Use test!output where it makes sense to ensure the output is equal to the expected value.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;b&gt;Calculations&lt;/b&gt;: Based on the calculation being run, identify inputs that will cover groupings of possible outcomes. The asserted output should be calculated outside of Appian and then asserted within the case.
&lt;ul&gt;
&lt;li&gt;For example, if you have a rule that is executing the following calculation: &lt;i&gt;A-B&lt;/i&gt;, with integers &lt;i&gt;A&lt;/i&gt; and &lt;i&gt;B&lt;/i&gt;, test cases should cover the following scenarios as they all would reveal something different about the calculation:
&lt;ul&gt;
&lt;li&gt;A&amp;gt;B (output is positive)&lt;/li&gt;
&lt;li&gt;A&amp;lt;B (output is negative)&lt;/li&gt;
&lt;li&gt;A=B (output is 0)&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;ul&gt;
&lt;li&gt;&lt;b&gt;Integrations: Expression Rule Test Cases can be used to test integration connectivity prior to a deployment. Create an expression rule that calls the integration and a test case that passes in data to populate the request. Set the assertion to &amp;ldquo;expression evaluates to true&amp;rdquo;. The expression should check that the &amp;ldquo;success&amp;rdquo; output of the integration = true. Add these expression rules to an app that is deployed prior to your business application.&lt;/b&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Date Times&lt;/strong&gt;:&amp;nbsp;Create test cases which cover all groupings of expected outcomes, including all known edge cases. Assert that the output is correct for each test case.&amp;nbsp;
&lt;ul&gt;
&lt;li&gt;For example, if a rule checks whether a date is a work day (calisworkday(datetime)), create test cases with the following inputs to test the possible outcomes. Use the value in parenthesis to assert that test!output is the correct value:
&lt;ul&gt;
&lt;li&gt;A work day (true)&lt;/li&gt;
&lt;li&gt;A weekend day (false)&lt;/li&gt;
&lt;li&gt;A holiday (false)&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;ul&gt;
&lt;li&gt;Consider test cases that go &amp;ldquo;stale&amp;rdquo; (rules where the output depends on whether inputs are in the past, future, etc). Avoid using hard coded dates and instead, use the appropriate Appian date and time functions (now(), today(), etc.) to ensure that test inputs will last for the lifetime of the application. As mentioned previously, do not use now() in test case assertions.&lt;/li&gt;
&lt;li&gt;If the rule contains calculations on dates in particular timezones, use the gmt() and local() functions to enforce a timezone and assert the correct output for that timezone.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;b&gt;Type Constructors&lt;/b&gt;:&amp;nbsp;Test cases are only necessary to test any logic within the rule that is outside of the constructor itself. &amp;ldquo;Assertion expression evaluates to true&amp;rdquo; is typically useful for these types of test cases.
&lt;ul&gt;
&lt;li&gt;If the rule takes a raw set of data and only casts items that meet specific criteria, a test case can be created in which you validate that all items in the output meet that criteria.&lt;/li&gt;
&lt;li&gt;If the rule casts individual fields from a rule input to a new data type, create a test case that asserts that each field equals what is expected by using test!output.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id="creating_error_handling_tests"&gt;Creating Error Handling Tests&lt;/h2&gt;
&lt;p&gt;Error handling test cases should be created based on the functions and inputs of the rule. &lt;b&gt;All &lt;/b&gt;rules should have null handling test cases (unless already covered by a parent rule), while other error handling scenarios should be determined at the Designer&amp;rsquo;s discretion. All error handling cases should have the test output match an asserted output.&lt;/p&gt;
&lt;h3 id="error_handling_test_case_examples"&gt;Error Handling Test Case Examples&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;&lt;b&gt;Null Handling: Set one, some, or all rule inputs to null to ensure the rule executes properly and outputs an expected value. In many cases, more than one null handling test case may be necessary.&lt;/b&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;div style="margin-bottom:3rem;margin-top:3rem;"&gt;&lt;img style="box-shadow:3px 3px 5px rgba(0, 0, 0, 0.1);" alt=" " src="/resized-image/__size/960x720/__key/communityserver-wikis-components-files/00-00-00-00-46/expressionImage1.png" /&gt;&lt;/div&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Invalid Mathematical Expressions&lt;/strong&gt;: In rules that execute a calculation, provide inputs that produce an invalid calculation, such as a denominator of zero. Ensure the rule still executes properly and outputs the expected value.
&lt;ul&gt;
&lt;li&gt;For example, if your rule is calculating the square root of the difference between &lt;i&gt;A &lt;/i&gt;and &lt;i&gt;B&lt;/i&gt;, create a case in which B &amp;gt; A.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;ul&gt;
&lt;li&gt;&lt;b&gt;Functions that error given invalid inputs: If a rule uses functions that produce an expression error if the input is invalid (e.g. user/group functions, not(), etc), create a test case for each invalid input to verify that expression errors are avoided.&lt;/b&gt;
&lt;ul&gt;
&lt;li&gt;For example, if your rule has a username input, cases should be created in which a random non-username string is passed in. The rule should be coded to handle this case properly.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Date Times&lt;/strong&gt;: Create test cases with datetimes outside of what the rule expects to ensure that the rule handles them appropriately.&lt;/li&gt;
&lt;/ul&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Queries&lt;/strong&gt;:&amp;nbsp;
&lt;ul&gt;
&lt;li&gt;For queries in which data is consistent across environments, regardless of user interaction with the system (i.e. reference data), create test cases with data that will always be returned and assert that the test output matches the desired value.&lt;/li&gt;
&lt;li&gt;For queries on transactional data, expression rule test cases should not be used to validate that a particular data set is returned because data can vary based on the environment and user interaction. However, test cases can still be used in the following ways:
&lt;ul&gt;
&lt;li&gt;On all expression rules that have queries, you can create a test case which asserts that the &amp;ldquo;&lt;a href="https://docs.appian.com/suite/help/20.3/Expression_Rules.html#test-case-assertions"&gt;Test completes without errors&lt;/a&gt;&amp;rdquo; to validate &lt;b&gt;database connectivity&lt;/b&gt;.&amp;nbsp;&lt;/li&gt;
&lt;li&gt;If the query ignores null filter values, include a test case which passes in values for all possible filters and asserts that the test completes without errors to ensure that all&lt;b&gt; field names and filter configurations&lt;/b&gt; are valid.&lt;/li&gt;
&lt;li&gt;If the query does not ignore null filter values, create &lt;b&gt;null-handling&lt;/b&gt; test cases for the rule.&amp;nbsp;&lt;/li&gt;
&lt;li&gt;For all filters that are created, test cases can be used to validate that the returned results match the&lt;b&gt; filter value&lt;/b&gt; that was passed in. For example, if &amp;ldquo;true&amp;rdquo; is passed into an &amp;ldquo;isActive&amp;rdquo; filter in the query, a test case can validate that all results returned have isActive=true. For test cases like these, include appropriate null handling for when no data matches the filter criteria.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Use test cases to assert that the output is of the same &lt;b&gt;data type&lt;/b&gt; as the data entity being queried. This can be done using the &amp;ldquo;&lt;a href="https://docs.appian.com/suite/help/20.3/Expression_Rules.html#test-case-assertions"&gt;Assertion expression evaluates to true&lt;/a&gt;&amp;rdquo; assertion option, where the expression would check that the type of test!output matches the expected type using the typeof() function.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;i&gt;Note: Expression rules containing queries should only include the a!queryEntity() function. Any expressions to manipulate the data or output different values based on the query results should be done in separate expression rules, using the results of the query as a rule input. This allows flexibility to assert that the manipulation or conditional output operates correctly without relying on transaction data that can change across Appian environments.&lt;/i&gt;&lt;/p&gt;
&lt;h2 id="example_expression_rule"&gt;Example Expression Rule&lt;/h2&gt;
&lt;h4&gt;An example expression rule that has coverage tests and error handling tests can be found below.&lt;/h4&gt;
&lt;div style="margin-bottom:3rem;margin-top:3rem;"&gt;&lt;img style="box-shadow:3px 3px 5px rgba(0, 0, 0, 0.1);" alt=" " src="/resized-image/__size/960x720/__key/communityserver-wikis-components-files/00-00-00-00-46/expressionImage2.png" /&gt;&lt;/div&gt;
&lt;div style="margin-bottom:3rem;margin-top:3rem;"&gt;&lt;img style="box-shadow:3px 3px 5px rgba(0, 0, 0, 0.1);" alt=" " src="/resized-image/__size/960x720/__key/communityserver-wikis-components-files/00-00-00-00-46/expressionImage3.png" /&gt;&lt;/div&gt;
&lt;p&gt;&lt;b&gt;Figure &lt;/b&gt;&lt;b&gt;&lt;i&gt;N&amp;nbsp;&lt;/i&gt;&lt;/b&gt;&lt;b&gt;: Sample Expression Rule&lt;/b&gt;&lt;/p&gt;
&lt;div style="margin-bottom:3rem;margin-top:3rem;"&gt;&lt;img style="box-shadow:3px 3px 5px rgba(0, 0, 0, 0.1);" alt=" " src="/resized-image/__size/960x720/__key/communityserver-wikis-components-files/00-00-00-00-46/expressionImage4.png" /&gt;&lt;/div&gt;
&lt;p&gt;&lt;b&gt;Figure &lt;/b&gt;&lt;b&gt;&lt;i&gt;M&amp;nbsp;&lt;/i&gt;&lt;/b&gt;&lt;b&gt;: Sample Test Cases&lt;/b&gt;&lt;/p&gt;
&lt;p&gt;These are test cases a user could have set up for the rule provided in &lt;b&gt;&lt;i&gt;Figure N&lt;/i&gt;&lt;/b&gt;. The first box contains &lt;b&gt;Coverage Tests&lt;/b&gt;. They provide code coverage by testing with expected inputs and outputs. The second box contains &lt;b&gt;Error Handling Tests&lt;/b&gt;. These tests are staged with inputs that would typically result in a denominator of 0. Finally, the third box contains &lt;b&gt;Null Handling Tests&lt;/b&gt;. This is another specific type of error handling tests. They are used to verify that our rule can properly handle null inputs. Note that more than one was required for this rule.&lt;/p&gt;
&lt;h2 id="regression_testing_with_test_cases"&gt;Regression Testing with Test Cases&lt;/h2&gt;
&lt;p&gt;Test cases make it easier and faster to regression test. Before making a change to an existing expression rule, run all existing test cases within the rule and resolve any that have failed. After making the change, add coverage and error handling test cases to test the change. Finally, run all test cases to ensure the update didn&amp;rsquo;t break any existing cases.&lt;/p&gt;
&lt;p&gt;Before a deployment, run the Automated Rules Testing Application (ART) in the target environment (non-production) to ensure all test cases work as expected before the deployment. If any rules do not work, resolve the issues in the lower environment prior to the deployment. After the deployment, re-run ART in the target environment to ensure all new and old test cases work as expected.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Note: These examples are not all-encompassing. Best judgement should be used to determine what cases are required.&lt;/p&gt;
&lt;/div&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;

&lt;div style="font-size: 90%;"&gt;Tags: testing, Architecture&lt;/div&gt;
</description></item><item><title>How to Create Expression Rule Test Cases</title><link>https://community.appian.com/success/w/guide/3342/how-to-create-expression-rule-test-cases/revision/11</link><pubDate>Thu, 11 Jan 2024 14:57:30 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:035ef30d-5bb9-47d1-85a5-ea78a8f96c19</guid><dc:creator>joel.larin</dc:creator><comments>https://community.appian.com/success/w/guide/3342/how-to-create-expression-rule-test-cases#comments</comments><description>Revision 11 posted to Guide by joel.larin on 1/11/2024 2:57:30 PM&lt;br /&gt;
&lt;div style="margin:8px 16% 8px 8%;"&gt;
&lt;p&gt;&lt;a href="https://docs.appian.com/suite/help/latest/Expression_Rules.html#test-cases"&gt;Expression rule test cases&lt;/a&gt; enable unit testing with minimal overhead by reducing the time required to test while increasing code quality. Because expression rules have a wide variety of uses, creating meaningful test cases will speed up unit, regression, and exploratory testing. Use the following guidelines to create test cases for your expression rules that will result in greater code coverage for your application. The first section provides guidelines for creating useful test cases, and the following sections explain types of expression rule test cases in greater detail with Appian examples.&lt;/p&gt;
&lt;div style="margin-top:22px;width:90%;"&gt;&lt;a href="https://youtu.be/vMuNwRFdty4?feature=shared"&gt;youtu.be/vMuNwRFdty4&lt;/a&gt;&lt;/div&gt;
&lt;h2 id="test_case_creation_guidelines"&gt;Test Case Creation Guidelines&lt;/h2&gt;
&lt;p&gt;The following guidelines apply to expression rules which output a value:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Create test cases from the start of application development to aid regression testing.&amp;nbsp;&lt;/li&gt;
&lt;li&gt;If an expression rule calls another expression rule, do not duplicate test cases already created in the child within the parent rule. The parent rule should contain test cases that test any logic within the parent rule itself and should assume the child has sufficient test cases.&lt;/li&gt;
&lt;li&gt;When possible, break down large expressions to individual rules so that it is easier to ensure test coverage with expression rule test cases&lt;/li&gt;
&lt;li&gt;When expression rule test cases are evaluated, the expression is evaluated first, followed by the assertion within the test case. Avoid the use of now() in test case assertions, as this can trigger false negatives due to the dateTime type evaluating the values down to the millisecond. Instead, check whether the field is not blank.&lt;/li&gt;
&lt;li&gt;Use test!output to assert the output equals what you would expect.&lt;/li&gt;
&lt;li&gt;Use &lt;a href="/w/guide/3339/exploratory-testing"&gt;Exploratory Testing&lt;/a&gt; to identify edge cases for which to create test cases.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id="types_of_test_cases"&gt;Types of Test Cases&lt;/h2&gt;
&lt;p&gt;When creating test cases, consider the two types of test cases: &lt;b&gt;coverage tests&lt;/b&gt; and &lt;b&gt;error handling&lt;/b&gt; tests. Every expression rule should always have at least one of each kind of test case.&lt;/p&gt;
&lt;table&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;p&gt;&lt;b&gt;Test Type&lt;/b&gt;&lt;/p&gt;
&lt;/td&gt;
&lt;td&gt;
&lt;p&gt;&lt;b&gt;Description&lt;/b&gt;&lt;/p&gt;
&lt;/td&gt;
&lt;td&gt;
&lt;p&gt;&lt;b&gt;Implementation&lt;/b&gt;&lt;/p&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;p&gt;Coverage&lt;/p&gt;
&lt;/td&gt;
&lt;td&gt;
&lt;p&gt;A coverage test ensures the rule inputs result in the intended output. In other words, an area of the rule has been sufficiently &amp;ldquo;covered&amp;rdquo; via a test case.&lt;/p&gt;
&lt;/td&gt;
&lt;td&gt;
&lt;p&gt;Set inputs to expected values.&amp;nbsp;&lt;/p&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;p&gt;Error Handling&lt;/p&gt;
&lt;/td&gt;
&lt;td&gt;
&lt;p&gt;An error handling test ensures the expression rule has proper error handling.&lt;/p&gt;
&lt;/td&gt;
&lt;td&gt;
&lt;p&gt;Set inputs to values that would typically break the rule.&lt;/p&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;h2 id="creating_coverage_tests"&gt;Creating Coverage Tests&lt;/h2&gt;
&lt;h3&gt;Use the diagram below to determine which test cases are required and how to set assertions.&lt;/h3&gt;
&lt;div style="margin-bottom:3rem;margin-top:3rem;"&gt;&lt;img style="box-shadow:3px 3px 5px rgba(0, 0, 0, 0.1);" alt=" " src="/resized-image/__size/640x480/__key/communityserver-wikis-components-files/00-00-00-00-46/expressionRuleFlow.jpg" /&gt;&lt;/div&gt;
&lt;h3 id="coverage_test_case_examples"&gt;Coverage Test Case Examples&lt;/h3&gt;
&lt;h3&gt;Limited Number of Outcomes&lt;/h3&gt;
&lt;p&gt;If your expression rule has a limited number of outcomes, use the below examples to guide your test case creation. Use test!output to assert that the output is equal to the value you expect. Each outcome should have a test case and corresponding assertion.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;b&gt;Nested if()s&lt;/b&gt;: Create 1 test case per possible condition&lt;/li&gt;
&lt;li&gt;&lt;b&gt;Choose()&lt;/b&gt;: Create 1 test case per key&lt;/li&gt;
&lt;li&gt;&lt;b&gt;Mathematical Comparisons&lt;/b&gt;: Create 1 test case per possible comparison&amp;nbsp;
&lt;ul&gt;
&lt;li&gt;For example, for a &lt;i&gt;greater than&lt;/i&gt; comparison, you must have 3 cases covering when the input is less than, equal to, or greater than the comparative value&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;Unlimited Number of Outcomes&lt;/h3&gt;
&lt;p&gt;If your expression rule has an unlimited number of outcomes, use the below examples to guide your test case creation. Use test!output where it makes sense to ensure the output is equal to the expected value.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;b&gt;Calculations&lt;/b&gt;: Based on the calculation being run, identify inputs that will cover groupings of possible outcomes. The asserted output should be calculated outside of Appian and then asserted within the case.
&lt;ul&gt;
&lt;li&gt;For example, if you have a rule that is executing the following calculation: &lt;i&gt;A-B&lt;/i&gt;, with integers &lt;i&gt;A&lt;/i&gt; and &lt;i&gt;B&lt;/i&gt;, test cases should cover the following scenarios as they all would reveal something different about the calculation:
&lt;ul&gt;
&lt;li&gt;A&amp;gt;B (output is positive)&lt;/li&gt;
&lt;li&gt;A&amp;lt;B (output is negative)&lt;/li&gt;
&lt;li&gt;A=B (output is 0)&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;ul&gt;
&lt;li&gt;&lt;b&gt;Integrations: Expression Rule Test Cases can be used to test integration connectivity prior to a deployment. Create an expression rule that calls the integration and a test case that passes in data to populate the request. Set the assertion to &amp;ldquo;expression evaluates to true&amp;rdquo;. The expression should check that the &amp;ldquo;success&amp;rdquo; output of the integration = true. Add these expression rules to an app that is deployed prior to your business application.&lt;/b&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Date Times&lt;/strong&gt;:&amp;nbsp;Create test cases which cover all groupings of expected outcomes, including all known edge cases. Assert that the output is correct for each test case.&amp;nbsp;
&lt;ul&gt;
&lt;li&gt;For example, if a rule checks whether a date is a work day (calisworkday(datetime)), create test cases with the following inputs to test the possible outcomes. Use the value in parenthesis to assert that test!output is the correct value:
&lt;ul&gt;
&lt;li&gt;A work day (true)&lt;/li&gt;
&lt;li&gt;A weekend day (false)&lt;/li&gt;
&lt;li&gt;A holiday (false)&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;ul&gt;
&lt;li&gt;Consider test cases that go &amp;ldquo;stale&amp;rdquo; (rules where the output depends on whether inputs are in the past, future, etc). Avoid using hard coded dates and instead, use the appropriate Appian date and time functions (now(), today(), etc.) to ensure that test inputs will last for the lifetime of the application. As mentioned previously, do not use now() in test case assertions.&lt;/li&gt;
&lt;li&gt;If the rule contains calculations on dates in particular timezones, use the gmt() and local() functions to enforce a timezone and assert the correct output for that timezone.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;b&gt;Type Constructors&lt;/b&gt;:&amp;nbsp;Test cases are only necessary to test any logic within the rule that is outside of the constructor itself. &amp;ldquo;Assertion expression evaluates to true&amp;rdquo; is typically useful for these types of test cases.
&lt;ul&gt;
&lt;li&gt;If the rule takes a raw set of data and only casts items that meet specific criteria, a test case can be created in which you validate that all items in the output meet that criteria.&lt;/li&gt;
&lt;li&gt;If the rule casts individual fields from a rule input to a new data type, create a test case that asserts that each field equals what is expected by using test!output.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id="creating_error_handling_tests"&gt;Creating Error Handling Tests&lt;/h2&gt;
&lt;p&gt;Error handling test cases should be created based on the functions and inputs of the rule. &lt;b&gt;All &lt;/b&gt;rules should have null handling test cases (unless already covered by a parent rule), while other error handling scenarios should be determined at the Designer&amp;rsquo;s discretion. All error handling cases should have the test output match an asserted output.&lt;/p&gt;
&lt;h3 id="error_handling_test_case_examples"&gt;Error Handling Test Case Examples&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;&lt;b&gt;Null Handling: Set one, some, or all rule inputs to null to ensure the rule executes properly and outputs an expected value. In many cases, more than one null handling test case may be necessary.&lt;/b&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;div style="margin-bottom:3rem;margin-top:3rem;"&gt;&lt;img style="box-shadow:3px 3px 5px rgba(0, 0, 0, 0.1);" alt=" " src="/resized-image/__size/960x720/__key/communityserver-wikis-components-files/00-00-00-00-46/expressionImage1.png" /&gt;&lt;/div&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Invalid Mathematical Expressions&lt;/strong&gt;: In rules that execute a calculation, provide inputs that produce an invalid calculation, such as a denominator of zero. Ensure the rule still executes properly and outputs the expected value.
&lt;ul&gt;
&lt;li&gt;For example, if your rule is calculating the square root of the difference between &lt;i&gt;A &lt;/i&gt;and &lt;i&gt;B&lt;/i&gt;, create a case in which B &amp;gt; A.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;ul&gt;
&lt;li&gt;&lt;b&gt;Functions that error given invalid inputs: If a rule uses functions that produce an expression error if the input is invalid (e.g. user/group functions, not(), etc), create a test case for each invalid input to verify that expression errors are avoided.&lt;/b&gt;
&lt;ul&gt;
&lt;li&gt;For example, if your rule has a username input, cases should be created in which a random non-username string is passed in. The rule should be coded to handle this case properly.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Date Times&lt;/strong&gt;: Create test cases with datetimes outside of what the rule expects to ensure that the rule handles them appropriately.&lt;/li&gt;
&lt;/ul&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Queries&lt;/strong&gt;:&amp;nbsp;
&lt;ul&gt;
&lt;li&gt;For queries in which data is consistent across environments, regardless of user interaction with the system (i.e. reference data), create test cases with data that will always be returned and assert that the test output matches the desired value.&lt;/li&gt;
&lt;li&gt;For queries on transactional data, expression rule test cases should not be used to validate that a particular data set is returned because data can vary based on the environment and user interaction. However, test cases can still be used in the following ways:
&lt;ul&gt;
&lt;li&gt;On all expression rules that have queries, you can create a test case which asserts that the &amp;ldquo;&lt;a href="https://docs.appian.com/suite/help/20.3/Expression_Rules.html#test-case-assertions"&gt;Test completes without errors&lt;/a&gt;&amp;rdquo; to validate &lt;b&gt;database connectivity&lt;/b&gt;.&amp;nbsp;&lt;/li&gt;
&lt;li&gt;If the query ignores null filter values, include a test case which passes in values for all possible filters and asserts that the test completes without errors to ensure that all&lt;b&gt; field names and filter configurations&lt;/b&gt; are valid.&lt;/li&gt;
&lt;li&gt;If the query does not ignore null filter values, create &lt;b&gt;null-handling&lt;/b&gt; test cases for the rule.&amp;nbsp;&lt;/li&gt;
&lt;li&gt;For all filters that are created, test cases can be used to validate that the returned results match the&lt;b&gt; filter value&lt;/b&gt; that was passed in. For example, if &amp;ldquo;true&amp;rdquo; is passed into an &amp;ldquo;isActive&amp;rdquo; filter in the query, a test case can validate that all results returned have isActive=true. For test cases like these, include appropriate null handling for when no data matches the filter criteria.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Use test cases to assert that the output is of the same &lt;b&gt;data type&lt;/b&gt; as the data entity being queried. This can be done using the &amp;ldquo;&lt;a href="https://docs.appian.com/suite/help/20.3/Expression_Rules.html#test-case-assertions"&gt;Assertion expression evaluates to true&lt;/a&gt;&amp;rdquo; assertion option, where the expression would check that the type of test!output matches the expected type using the typeof() function.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;i&gt;Note: Expression rules containing queries should only include the a!queryEntity() function. Any expressions to manipulate the data or output different values based on the query results should be done in separate expression rules, using the results of the query as a rule input. This allows flexibility to assert that the manipulation or conditional output operates correctly without relying on transaction data that can change across Appian environments.&lt;/i&gt;&lt;/p&gt;
&lt;h2 id="example_expression_rule"&gt;Example Expression Rule&lt;/h2&gt;
&lt;h4&gt;An example expression rule that has coverage tests and error handling tests can be found below.&lt;/h4&gt;
&lt;div style="margin-bottom:3rem;margin-top:3rem;"&gt;&lt;img style="box-shadow:3px 3px 5px rgba(0, 0, 0, 0.1);" alt=" " src="/resized-image/__size/960x720/__key/communityserver-wikis-components-files/00-00-00-00-46/expressionImage2.png" /&gt;&lt;/div&gt;
&lt;div style="margin-bottom:3rem;margin-top:3rem;"&gt;&lt;img style="box-shadow:3px 3px 5px rgba(0, 0, 0, 0.1);" alt=" " src="/resized-image/__size/960x720/__key/communityserver-wikis-components-files/00-00-00-00-46/expressionImage3.png" /&gt;&lt;/div&gt;
&lt;p&gt;&lt;b&gt;Figure &lt;/b&gt;&lt;b&gt;&lt;i&gt;N&amp;nbsp;&lt;/i&gt;&lt;/b&gt;&lt;b&gt;: Sample Expression Rule&lt;/b&gt;&lt;/p&gt;
&lt;div style="margin-bottom:3rem;margin-top:3rem;"&gt;&lt;img style="box-shadow:3px 3px 5px rgba(0, 0, 0, 0.1);" alt=" " src="/resized-image/__size/960x720/__key/communityserver-wikis-components-files/00-00-00-00-46/expressionImage4.png" /&gt;&lt;/div&gt;
&lt;p&gt;&lt;b&gt;Figure &lt;/b&gt;&lt;b&gt;&lt;i&gt;M&amp;nbsp;&lt;/i&gt;&lt;/b&gt;&lt;b&gt;: Sample Test Cases&lt;/b&gt;&lt;/p&gt;
&lt;p&gt;These are test cases a user could have set up for the rule provided in &lt;b&gt;&lt;i&gt;Figure N&lt;/i&gt;&lt;/b&gt;. The first box contains &lt;b&gt;Coverage Tests&lt;/b&gt;. They provide code coverage by testing with expected inputs and outputs. The second box contains &lt;b&gt;Error Handling Tests&lt;/b&gt;. These tests are staged with inputs that would typically result in a denominator of 0. Finally, the third box contains &lt;b&gt;Null Handling Tests&lt;/b&gt;. This is another specific type of error handling tests. They are used to verify that our rule can properly handle null inputs. Note that more than one was required for this rule.&lt;/p&gt;
&lt;h2 id="regression_testing_with_test_cases"&gt;Regression Testing with Test Cases&lt;/h2&gt;
&lt;p&gt;Test cases make it easier and faster to regression test. Before making a change to an existing expression rule, run all existing test cases within the rule and resolve any that have failed. After making the change, add coverage and error handling test cases to test the change. Finally, run all test cases to ensure the update didn&amp;rsquo;t break any existing cases.&lt;/p&gt;
&lt;p&gt;Before a deployment, run the Automated Rules Testing Application (ART) in the target environment (non-production) to ensure all test cases work as expected before the deployment. If any rules do not work, resolve the issues in the lower environment prior to the deployment. After the deployment, re-run ART in the target environment to ensure all new and old test cases work as expected.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Note: These examples are not all-encompassing. Best judgement should be used to determine what cases are required.&lt;/p&gt;
&lt;/div&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;

&lt;div style="font-size: 90%;"&gt;Tags: testing, Architecture&lt;/div&gt;
</description></item><item><title>How to Create Expression Rule Test Cases</title><link>https://community.appian.com/success/w/guide/3342/how-to-create-expression-rule-test-cases/revision/10</link><pubDate>Tue, 31 Oct 2023 16:07:22 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:035ef30d-5bb9-47d1-85a5-ea78a8f96c19</guid><dc:creator>joel.larin</dc:creator><comments>https://community.appian.com/success/w/guide/3342/how-to-create-expression-rule-test-cases#comments</comments><description>Revision 10 posted to Guide by joel.larin on 10/31/2023 4:07:22 PM&lt;br /&gt;
&lt;div style="margin:8px 16% 8px 8%;"&gt;
&lt;p&gt;&lt;a href="https://docs.appian.com/suite/help/latest/Expression_Rules.html#test-cases"&gt;Expression rule test cases&lt;/a&gt; enable unit testing with minimal overhead by reducing the time required to test while increasing code quality. Because expression rules have a wide variety of uses, creating meaningful test cases will speed up unit, regression, and exploratory testing. Use the following guidelines to create test cases for your expression rules that will result in greater code coverage for your application. The first section provides guidelines for creating useful test cases, and the following sections explain types of expression rule test cases in greater detail with Appian examples.&lt;/p&gt;
&lt;h2 id="test_case_creation_guidelines"&gt;Test Case Creation Guidelines&lt;/h2&gt;
&lt;p&gt;The following guidelines apply to expression rules which output a value:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Create test cases from the start of application development to aid regression testing.&amp;nbsp;&lt;/li&gt;
&lt;li&gt;If an expression rule calls another expression rule, do not duplicate test cases already created in the child within the parent rule. The parent rule should contain test cases that test any logic within the parent rule itself and should assume the child has sufficient test cases.&lt;/li&gt;
&lt;li&gt;When possible, break down large expressions to individual rules so that it is easier to ensure test coverage with expression rule test cases&lt;/li&gt;
&lt;li&gt;When expression rule test cases are evaluated, the expression is evaluated first, followed by the assertion within the test case. Avoid the use of now() in test case assertions, as this can trigger false negatives due to the dateTime type evaluating the values down to the millisecond. Instead, check whether the field is not blank.&lt;/li&gt;
&lt;li&gt;Use test!output to assert the output equals what you would expect.&lt;/li&gt;
&lt;li&gt;Use &lt;a href="/w/guide/3339/exploratory-testing"&gt;Exploratory Testing&lt;/a&gt; to identify edge cases for which to create test cases.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id="types_of_test_cases"&gt;Types of Test Cases&lt;/h2&gt;
&lt;p&gt;When creating test cases, consider the two types of test cases: &lt;b&gt;coverage tests&lt;/b&gt; and &lt;b&gt;error handling&lt;/b&gt; tests. Every expression rule should always have at least one of each kind of test case.&lt;/p&gt;
&lt;table&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;p&gt;&lt;b&gt;Test Type&lt;/b&gt;&lt;/p&gt;
&lt;/td&gt;
&lt;td&gt;
&lt;p&gt;&lt;b&gt;Description&lt;/b&gt;&lt;/p&gt;
&lt;/td&gt;
&lt;td&gt;
&lt;p&gt;&lt;b&gt;Implementation&lt;/b&gt;&lt;/p&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;p&gt;Coverage&lt;/p&gt;
&lt;/td&gt;
&lt;td&gt;
&lt;p&gt;A coverage test ensures the rule inputs result in the intended output. In other words, an area of the rule has been sufficiently &amp;ldquo;covered&amp;rdquo; via a test case.&lt;/p&gt;
&lt;/td&gt;
&lt;td&gt;
&lt;p&gt;Set inputs to expected values.&amp;nbsp;&lt;/p&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;p&gt;Error Handling&lt;/p&gt;
&lt;/td&gt;
&lt;td&gt;
&lt;p&gt;An error handling test ensures the expression rule has proper error handling.&lt;/p&gt;
&lt;/td&gt;
&lt;td&gt;
&lt;p&gt;Set inputs to values that would typically break the rule.&lt;/p&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;h2 id="creating_coverage_tests"&gt;Creating Coverage Tests&lt;/h2&gt;
&lt;h3&gt;Use the diagram below to determine which test cases are required and how to set assertions.&lt;/h3&gt;
&lt;div style="margin-bottom:3rem;margin-top:3rem;"&gt;&lt;img style="box-shadow:3px 3px 5px rgba(0, 0, 0, 0.1);" alt=" " src="/resized-image/__size/640x480/__key/communityserver-wikis-components-files/00-00-00-00-46/expressionRuleFlow.jpg" /&gt;&lt;/div&gt;
&lt;h3 id="coverage_test_case_examples"&gt;Coverage Test Case Examples&lt;/h3&gt;
&lt;h3&gt;Limited Number of Outcomes&lt;/h3&gt;
&lt;p&gt;If your expression rule has a limited number of outcomes, use the below examples to guide your test case creation. Use test!output to assert that the output is equal to the value you expect. Each outcome should have a test case and corresponding assertion.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;b&gt;Nested if()s&lt;/b&gt;: Create 1 test case per possible condition&lt;/li&gt;
&lt;li&gt;&lt;b&gt;Choose()&lt;/b&gt;: Create 1 test case per key&lt;/li&gt;
&lt;li&gt;&lt;b&gt;Mathematical Comparisons&lt;/b&gt;: Create 1 test case per possible comparison&amp;nbsp;
&lt;ul&gt;
&lt;li&gt;For example, for a &lt;i&gt;greater than&lt;/i&gt; comparison, you must have 3 cases covering when the input is less than, equal to, or greater than the comparative value&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;Unlimited Number of Outcomes&lt;/h3&gt;
&lt;p&gt;If your expression rule has an unlimited number of outcomes, use the below examples to guide your test case creation. Use test!output where it makes sense to ensure the output is equal to the expected value.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;b&gt;Calculations&lt;/b&gt;: Based on the calculation being run, identify inputs that will cover groupings of possible outcomes. The asserted output should be calculated outside of Appian and then asserted within the case.
&lt;ul&gt;
&lt;li&gt;For example, if you have a rule that is executing the following calculation: &lt;i&gt;A-B&lt;/i&gt;, with integers &lt;i&gt;A&lt;/i&gt; and &lt;i&gt;B&lt;/i&gt;, test cases should cover the following scenarios as they all would reveal something different about the calculation:
&lt;ul&gt;
&lt;li&gt;A&amp;gt;B (output is positive)&lt;/li&gt;
&lt;li&gt;A&amp;lt;B (output is negative)&lt;/li&gt;
&lt;li&gt;A=B (output is 0)&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;ul&gt;
&lt;li&gt;&lt;b&gt;Integrations: Expression Rule Test Cases can be used to test integration connectivity prior to a deployment. Create an expression rule that calls the integration and a test case that passes in data to populate the request. Set the assertion to &amp;ldquo;expression evaluates to true&amp;rdquo;. The expression should check that the &amp;ldquo;success&amp;rdquo; output of the integration = true. Add these expression rules to an app that is deployed prior to your business application.&lt;/b&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Date Times&lt;/strong&gt;:&amp;nbsp;Create test cases which cover all groupings of expected outcomes, including all known edge cases. Assert that the output is correct for each test case.&amp;nbsp;
&lt;ul&gt;
&lt;li&gt;For example, if a rule checks whether a date is a work day (calisworkday(datetime)), create test cases with the following inputs to test the possible outcomes. Use the value in parenthesis to assert that test!output is the correct value:
&lt;ul&gt;
&lt;li&gt;A work day (true)&lt;/li&gt;
&lt;li&gt;A weekend day (false)&lt;/li&gt;
&lt;li&gt;A holiday (false)&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;ul&gt;
&lt;li&gt;Consider test cases that go &amp;ldquo;stale&amp;rdquo; (rules where the output depends on whether inputs are in the past, future, etc). Avoid using hard coded dates and instead, use the appropriate Appian date and time functions (now(), today(), etc.) to ensure that test inputs will last for the lifetime of the application. As mentioned previously, do not use now() in test case assertions.&lt;/li&gt;
&lt;li&gt;If the rule contains calculations on dates in particular timezones, use the gmt() and local() functions to enforce a timezone and assert the correct output for that timezone.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;b&gt;Type Constructors&lt;/b&gt;:&amp;nbsp;Test cases are only necessary to test any logic within the rule that is outside of the constructor itself. &amp;ldquo;Assertion expression evaluates to true&amp;rdquo; is typically useful for these types of test cases.
&lt;ul&gt;
&lt;li&gt;If the rule takes a raw set of data and only casts items that meet specific criteria, a test case can be created in which you validate that all items in the output meet that criteria.&lt;/li&gt;
&lt;li&gt;If the rule casts individual fields from a rule input to a new data type, create a test case that asserts that each field equals what is expected by using test!output.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id="creating_error_handling_tests"&gt;Creating Error Handling Tests&lt;/h2&gt;
&lt;p&gt;Error handling test cases should be created based on the functions and inputs of the rule. &lt;b&gt;All &lt;/b&gt;rules should have null handling test cases (unless already covered by a parent rule), while other error handling scenarios should be determined at the Designer&amp;rsquo;s discretion. All error handling cases should have the test output match an asserted output.&lt;/p&gt;
&lt;h3 id="error_handling_test_case_examples"&gt;Error Handling Test Case Examples&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;&lt;b&gt;Null Handling: Set one, some, or all rule inputs to null to ensure the rule executes properly and outputs an expected value. In many cases, more than one null handling test case may be necessary.&lt;/b&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;div style="margin-bottom:3rem;margin-top:3rem;"&gt;&lt;img style="box-shadow:3px 3px 5px rgba(0, 0, 0, 0.1);" alt=" " src="/resized-image/__size/960x720/__key/communityserver-wikis-components-files/00-00-00-00-46/expressionImage1.png" /&gt;&lt;/div&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Invalid Mathematical Expressions&lt;/strong&gt;: In rules that execute a calculation, provide inputs that produce an invalid calculation, such as a denominator of zero. Ensure the rule still executes properly and outputs the expected value.
&lt;ul&gt;
&lt;li&gt;For example, if your rule is calculating the square root of the difference between &lt;i&gt;A &lt;/i&gt;and &lt;i&gt;B&lt;/i&gt;, create a case in which B &amp;gt; A.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;ul&gt;
&lt;li&gt;&lt;b&gt;Functions that error given invalid inputs: If a rule uses functions that produce an expression error if the input is invalid (e.g. user/group functions, not(), etc), create a test case for each invalid input to verify that expression errors are avoided.&lt;/b&gt;
&lt;ul&gt;
&lt;li&gt;For example, if your rule has a username input, cases should be created in which a random non-username string is passed in. The rule should be coded to handle this case properly.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Date Times&lt;/strong&gt;: Create test cases with datetimes outside of what the rule expects to ensure that the rule handles them appropriately.&lt;/li&gt;
&lt;/ul&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Queries&lt;/strong&gt;:&amp;nbsp;
&lt;ul&gt;
&lt;li&gt;For queries in which data is consistent across environments, regardless of user interaction with the system (i.e. reference data), create test cases with data that will always be returned and assert that the test output matches the desired value.&lt;/li&gt;
&lt;li&gt;For queries on transactional data, expression rule test cases should not be used to validate that a particular data set is returned because data can vary based on the environment and user interaction. However, test cases can still be used in the following ways:
&lt;ul&gt;
&lt;li&gt;On all expression rules that have queries, you can create a test case which asserts that the &amp;ldquo;&lt;a href="https://docs.appian.com/suite/help/20.3/Expression_Rules.html#test-case-assertions"&gt;Test completes without errors&lt;/a&gt;&amp;rdquo; to validate &lt;b&gt;database connectivity&lt;/b&gt;.&amp;nbsp;&lt;/li&gt;
&lt;li&gt;If the query ignores null filter values, include a test case which passes in values for all possible filters and asserts that the test completes without errors to ensure that all&lt;b&gt; field names and filter configurations&lt;/b&gt; are valid.&lt;/li&gt;
&lt;li&gt;If the query does not ignore null filter values, create &lt;b&gt;null-handling&lt;/b&gt; test cases for the rule.&amp;nbsp;&lt;/li&gt;
&lt;li&gt;For all filters that are created, test cases can be used to validate that the returned results match the&lt;b&gt; filter value&lt;/b&gt; that was passed in. For example, if &amp;ldquo;true&amp;rdquo; is passed into an &amp;ldquo;isActive&amp;rdquo; filter in the query, a test case can validate that all results returned have isActive=true. For test cases like these, include appropriate null handling for when no data matches the filter criteria.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Use test cases to assert that the output is of the same &lt;b&gt;data type&lt;/b&gt; as the data entity being queried. This can be done using the &amp;ldquo;&lt;a href="https://docs.appian.com/suite/help/20.3/Expression_Rules.html#test-case-assertions"&gt;Assertion expression evaluates to true&lt;/a&gt;&amp;rdquo; assertion option, where the expression would check that the type of test!output matches the expected type using the typeof() function.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;i&gt;Note: Expression rules containing queries should only include the a!queryEntity() function. Any expressions to manipulate the data or output different values based on the query results should be done in separate expression rules, using the results of the query as a rule input. This allows flexibility to assert that the manipulation or conditional output operates correctly without relying on transaction data that can change across Appian environments.&lt;/i&gt;&lt;/p&gt;
&lt;h2 id="example_expression_rule"&gt;Example Expression Rule&lt;/h2&gt;
&lt;h4&gt;An example expression rule that has coverage tests and error handling tests can be found below.&lt;/h4&gt;
&lt;div style="margin-bottom:3rem;margin-top:3rem;"&gt;&lt;img style="box-shadow:3px 3px 5px rgba(0, 0, 0, 0.1);" alt=" " src="/resized-image/__size/960x720/__key/communityserver-wikis-components-files/00-00-00-00-46/expressionImage2.png" /&gt;&lt;/div&gt;
&lt;div style="margin-bottom:3rem;margin-top:3rem;"&gt;&lt;img style="box-shadow:3px 3px 5px rgba(0, 0, 0, 0.1);" alt=" " src="/resized-image/__size/960x720/__key/communityserver-wikis-components-files/00-00-00-00-46/expressionImage3.png" /&gt;&lt;/div&gt;
&lt;p&gt;&lt;b&gt;Figure &lt;/b&gt;&lt;b&gt;&lt;i&gt;N&amp;nbsp;&lt;/i&gt;&lt;/b&gt;&lt;b&gt;: Sample Expression Rule&lt;/b&gt;&lt;/p&gt;
&lt;div style="margin-bottom:3rem;margin-top:3rem;"&gt;&lt;img style="box-shadow:3px 3px 5px rgba(0, 0, 0, 0.1);" alt=" " src="/resized-image/__size/960x720/__key/communityserver-wikis-components-files/00-00-00-00-46/expressionImage4.png" /&gt;&lt;/div&gt;
&lt;p&gt;&lt;b&gt;Figure &lt;/b&gt;&lt;b&gt;&lt;i&gt;M&amp;nbsp;&lt;/i&gt;&lt;/b&gt;&lt;b&gt;: Sample Test Cases&lt;/b&gt;&lt;/p&gt;
&lt;p&gt;These are test cases a user could have set up for the rule provided in &lt;b&gt;&lt;i&gt;Figure N&lt;/i&gt;&lt;/b&gt;. The first box contains &lt;b&gt;Coverage Tests&lt;/b&gt;. They provide code coverage by testing with expected inputs and outputs. The second box contains &lt;b&gt;Error Handling Tests&lt;/b&gt;. These tests are staged with inputs that would typically result in a denominator of 0. Finally, the third box contains &lt;b&gt;Null Handling Tests&lt;/b&gt;. This is another specific type of error handling tests. They are used to verify that our rule can properly handle null inputs. Note that more than one was required for this rule.&lt;/p&gt;
&lt;h2 id="regression_testing_with_test_cases"&gt;Regression Testing with Test Cases&lt;/h2&gt;
&lt;p&gt;Test cases make it easier and faster to regression test. Before making a change to an existing expression rule, run all existing test cases within the rule and resolve any that have failed. After making the change, add coverage and error handling test cases to test the change. Finally, run all test cases to ensure the update didn&amp;rsquo;t break any existing cases.&lt;/p&gt;
&lt;p&gt;Before a deployment, run the Automated Rules Testing Application (ART) in the target environment (non-production) to ensure all test cases work as expected before the deployment. If any rules do not work, resolve the issues in the lower environment prior to the deployment. After the deployment, re-run ART in the target environment to ensure all new and old test cases work as expected.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Note: These examples are not all-encompassing. Best judgement should be used to determine what cases are required.&lt;/p&gt;
&lt;/div&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;

&lt;div style="font-size: 90%;"&gt;Tags: testing, Architecture&lt;/div&gt;
</description></item><item><title>How to Create Expression Rule Test Cases</title><link>https://community.appian.com/success/w/guide/3342/how-to-create-expression-rule-test-cases/revision/9</link><pubDate>Tue, 31 Oct 2023 15:06:27 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:035ef30d-5bb9-47d1-85a5-ea78a8f96c19</guid><dc:creator>joel.larin</dc:creator><comments>https://community.appian.com/success/w/guide/3342/how-to-create-expression-rule-test-cases#comments</comments><description>Revision 9 posted to Guide by joel.larin on 10/31/2023 3:06:27 PM&lt;br /&gt;
&lt;div style="margin:8px 16% 8px 8%;"&gt;
&lt;p&gt;&lt;a href="https://docs.appian.com/suite/help/latest/Expression_Rules.html#test-cases"&gt;Expression rule test cases&lt;/a&gt; enable unit testing with minimal overhead by reducing the time required to test while increasing code quality. Because expression rules have a wide variety of uses, creating meaningful test cases will speed up unit, regression, and exploratory testing. Use the following guidelines to create test cases for your expression rules that will result in greater code coverage for your application. The first section provides guidelines for creating useful test cases, and the following sections explain types of expression rule test cases in greater detail with Appian examples.&lt;/p&gt;
&lt;h2 id="test_case_creation_guidelines"&gt;Test Case Creation Guidelines&lt;/h2&gt;
&lt;p&gt;The following guidelines apply to expression rules which output a value:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Create test cases from the start of application development to aid regression testing.&amp;nbsp;&lt;/li&gt;
&lt;li&gt;If an expression rule calls another expression rule, do not duplicate test cases already created in the child within the parent rule. The parent rule should contain test cases that test any logic within the parent rule itself and should assume the child has sufficient test cases.&lt;/li&gt;
&lt;li&gt;When possible, break down large expressions to individual rules so that it is easier to ensure test coverage with expression rule test cases&lt;/li&gt;
&lt;li&gt;When expression rule test cases are evaluated, the expression is evaluated first, followed by the assertion within the test case. Avoid the use of now() in test case assertions, as this can trigger false negatives due to the dateTime type evaluating the values down to the millisecond. Instead, check whether the field is not blank.&lt;/li&gt;
&lt;li&gt;Use test!output to assert the output equals what you would expect.&lt;/li&gt;
&lt;li&gt;Use &lt;a href="/w/guide/3339/exploratory-testing"&gt;Exploratory Testing&lt;/a&gt; to identify edge cases for which to create test cases.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id="types_of_test_cases"&gt;Types of Test Cases&lt;/h2&gt;
&lt;p&gt;When creating test cases, consider the two types of test cases: &lt;b&gt;coverage tests&lt;/b&gt; and &lt;b&gt;error handling&lt;/b&gt; tests. Every expression rule should always have at least one of each kind of test case.&lt;/p&gt;
&lt;table&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;p&gt;&lt;b&gt;Test Type&lt;/b&gt;&lt;/p&gt;
&lt;/td&gt;
&lt;td&gt;
&lt;p&gt;&lt;b&gt;Description&lt;/b&gt;&lt;/p&gt;
&lt;/td&gt;
&lt;td&gt;
&lt;p&gt;&lt;b&gt;Implementation&lt;/b&gt;&lt;/p&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;p&gt;Coverage&lt;/p&gt;
&lt;/td&gt;
&lt;td&gt;
&lt;p&gt;A coverage test ensures the rule inputs result in the intended output. In other words, an area of the rule has been sufficiently &amp;ldquo;covered&amp;rdquo; via a test case.&lt;/p&gt;
&lt;/td&gt;
&lt;td&gt;
&lt;p&gt;Set inputs to expected values.&amp;nbsp;&lt;/p&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;p&gt;Error Handling&lt;/p&gt;
&lt;/td&gt;
&lt;td&gt;
&lt;p&gt;An error handling test ensures the expression rule has proper error handling.&lt;/p&gt;
&lt;/td&gt;
&lt;td&gt;
&lt;p&gt;Set inputs to values that would typically break the rule.&lt;/p&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;h2 id="creating_coverage_tests"&gt;Creating Coverage Tests&lt;/h2&gt;
&lt;h3&gt;Use the diagram below to determine which test cases are required and how to set assertions.&lt;/h3&gt;
&lt;div style="margin-bottom:3rem;margin-top:3rem;"&gt;&lt;img style="box-shadow:3px 3px 5px rgba(0, 0, 0, 0.1);" alt=" " src="/resized-image/__size/640x480/__key/communityserver-wikis-components-files/00-00-00-00-46/expressionRuleFlow.jpg" /&gt;&lt;/div&gt;
&lt;h3 id="coverage_test_case_examples"&gt;Coverage Test Case Examples&lt;/h3&gt;
&lt;h3&gt;Limited Number of Outcomes&lt;/h3&gt;
&lt;p&gt;If your expression rule has a limited number of outcomes, use the below examples to guide your test case creation. Use test!output to assert that the output is equal to the value you expect. Each outcome should have a test case and corresponding assertion.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;b&gt;Nested if()s&lt;/b&gt;: Create 1 test case per possible condition&lt;/li&gt;
&lt;li&gt;&lt;b&gt;Choose()&lt;/b&gt;: Create 1 test case per key&lt;/li&gt;
&lt;li&gt;&lt;b&gt;Mathematical Comparisons&lt;/b&gt;: Create 1 test case per possible comparison&amp;nbsp;
&lt;ul&gt;
&lt;li&gt;For example, for a &lt;i&gt;greater than&lt;/i&gt; comparison, you must have 3 cases covering when the input is less than, equal to, or greater than the comparative value&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;Unlimited Number of Outcomes&lt;/h3&gt;
&lt;p&gt;If your expression rule has an unlimited number of outcomes, use the below examples to guide your test case creation. Use test!output where it makes sense to ensure the output is equal to the expected value.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;b&gt;Calculations&lt;/b&gt;: Based on the calculation being run, identify inputs that will cover groupings of possible outcomes. The asserted output should be calculated outside of Appian and then asserted within the case.
&lt;ul&gt;
&lt;li&gt;For example, if you have a rule that is executing the following calculation: &lt;i&gt;A-B&lt;/i&gt;, with integers &lt;i&gt;A&lt;/i&gt; and &lt;i&gt;B&lt;/i&gt;, test cases should cover the following scenarios as they all would reveal something different about the calculation:
&lt;ul&gt;
&lt;li&gt;A&amp;gt;B (output is positive)&lt;/li&gt;
&lt;li&gt;A&amp;lt;B (output is negative)&lt;/li&gt;
&lt;li&gt;A=B (output is 0)&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;ul&gt;
&lt;li&gt;&lt;b&gt;Integrations: Expression Rule Test Cases can be used to test integration connectivity prior to a deployment. Create an expression rule that calls the integration and a test case that passes in data to populate the request. Set the assertion to &amp;ldquo;expression evaluates to true&amp;rdquo;. The expression should check that the &amp;ldquo;success&amp;rdquo; output of the integration = true. Add these expression rules to an app that is deployed prior to your business application.&lt;/b&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Date Times&lt;/strong&gt;:&amp;nbsp;Create test cases which cover all groupings of expected outcomes, including all known edge cases. Assert that the output is correct for each test case.&amp;nbsp;
&lt;ul&gt;
&lt;li&gt;For example, if a rule checks whether a date is a work day (calisworkday(datetime)), create test cases with the following inputs to test the possible outcomes. Use the value in parenthesis to assert that test!output is the correct value:
&lt;ul&gt;
&lt;li&gt;A work day (true)&lt;/li&gt;
&lt;li&gt;A weekend day (false)&lt;/li&gt;
&lt;li&gt;A holiday (false)&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;ul&gt;
&lt;li&gt;Consider test cases that go &amp;ldquo;stale&amp;rdquo; (rules where the output depends on whether inputs are in the past, future, etc). Avoid using hard coded dates and instead, use the appropriate Appian date and time functions (now(), today(), etc.) to ensure that test inputs will last for the lifetime of the application. As mentioned previously, do not use now() in test case assertions.&lt;/li&gt;
&lt;li&gt;If the rule contains calculations on dates in particular timezones, use the gmt() and local() functions to enforce a timezone and assert the correct output for that timezone.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;b&gt;Type Constructors&lt;/b&gt;:&amp;nbsp;Test cases are only necessary to test any logic within the rule that is outside of the constructor itself. &amp;ldquo;Assertion expression evaluates to true&amp;rdquo; is typically useful for these types of test cases.
&lt;ul&gt;
&lt;li&gt;If the rule takes a raw set of data and only casts items that meet specific criteria, a test case can be created in which you validate that all items in the output meet that criteria.&lt;/li&gt;
&lt;li&gt;If the rule casts individual fields from a rule input to a new data type, create a test case that asserts that each field equals what is expected by using test!output.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id="creating_error_handling_tests"&gt;Creating Error Handling Tests&lt;/h2&gt;
&lt;p&gt;Error handling test cases should be created based on the functions and inputs of the rule. &lt;b&gt;All &lt;/b&gt;rules should have null handling test cases (unless already covered by a parent rule), while other error handling scenarios should be determined at the Designer&amp;rsquo;s discretion. All error handling cases should have the test output match an asserted output.&lt;/p&gt;
&lt;h3 id="error_handling_test_case_examples"&gt;Error Handling Test Case Examples&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;&lt;b&gt;Null Handling: Set one, some, or all rule inputs to null to ensure the rule executes properly and outputs an expected value. In many cases, more than one null handling test case may be necessary.&lt;/b&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;div style="margin-bottom:3rem;margin-top:3rem;"&gt;&lt;img style="box-shadow:3px 3px 5px rgba(0, 0, 0, 0.1);" alt=" " src="/resized-image/__size/960x720/__key/communityserver-wikis-components-files/00-00-00-00-46/expressionImage1.png" /&gt;&lt;/div&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Invalid Mathematical Expressions&lt;/strong&gt;: In rules that execute a calculation, provide inputs that produce an invalid calculation, such as a denominator of zero. Ensure the rule still executes properly and outputs the expected value.
&lt;ul&gt;
&lt;li&gt;For example, if your rule is calculating the square root of the difference between &lt;i&gt;A &lt;/i&gt;and &lt;i&gt;B&lt;/i&gt;, create a case in which B &amp;gt; A.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;ul&gt;
&lt;li&gt;&lt;b&gt;Functions that error given invalid inputs: If a rule uses functions that produce an expression error if the input is invalid (e.g. user/group functions, not(), etc), create a test case for each invalid input to verify that expression errors are avoided.&lt;/b&gt;
&lt;ul&gt;
&lt;li&gt;For example, if your rule has a username input, cases should be created in which a random non-username string is passed in. The rule should be coded to handle this case properly.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Date Times&lt;/strong&gt;: Create test cases with datetimes outside of what the rule expects to ensure that the rule handles them appropriately.&lt;/li&gt;
&lt;/ul&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Queries&lt;/strong&gt;:&amp;nbsp;
&lt;ul&gt;
&lt;li&gt;For queries in which data is consistent across environments, regardless of user interaction with the system (i.e. reference data), create test cases with data that will always be returned and assert that the test output matches the desired value.&lt;/li&gt;
&lt;li&gt;For queries on transactional data, expression rule test cases should not be used to validate that a particular data set is returned because data can vary based on the environment and user interaction. However, test cases can still be used in the following ways:
&lt;ul&gt;
&lt;li&gt;On all expression rules that have queries, you can create a test case which asserts that the &amp;ldquo;&lt;a href="https://docs.appian.com/suite/help/20.3/Expression_Rules.html#test-case-assertions"&gt;Test completes without errors&lt;/a&gt;&amp;rdquo; to validate &lt;b&gt;database connectivity&lt;/b&gt;.&amp;nbsp;&lt;/li&gt;
&lt;li&gt;If the query ignores null filter values, include a test case which passes in values for all possible filters and asserts that the test completes without errors to ensure that all&lt;b&gt; field names and filter configurations&lt;/b&gt; are valid.&lt;/li&gt;
&lt;li&gt;If the query does not ignore null filter values, create &lt;b&gt;null-handling&lt;/b&gt; test cases for the rule.&amp;nbsp;&lt;/li&gt;
&lt;li&gt;For all filters that are created, test cases can be used to validate that the returned results match the&lt;b&gt; filter value&lt;/b&gt; that was passed in. For example, if &amp;ldquo;true&amp;rdquo; is passed into an &amp;ldquo;isActive&amp;rdquo; filter in the query, a test case can validate that all results returned have isActive=true. For test cases like these, include appropriate null handling for when no data matches the filter criteria.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Use test cases to assert that the output is of the same &lt;b&gt;data type&lt;/b&gt; as the data entity being queried. This can be done using the &amp;ldquo;&lt;a href="https://docs.appian.com/suite/help/20.3/Expression_Rules.html#test-case-assertions"&gt;Assertion expression evaluates to true&lt;/a&gt;&amp;rdquo; assertion option, where the expression would check that the type of test!output matches the expected type using the typeof() function.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;i&gt;Note: Expression rules containing queries should only include the a!queryEntity() function. Any expressions to manipulate the data or output different values based on the query results should be done in separate expression rules, using the results of the query as a rule input. This allows flexibility to assert that the manipulation or conditional output operates correctly without relying on transaction data that can change across Appian environments.&lt;/i&gt;&lt;/p&gt;
&lt;h2 id="example_expression_rule"&gt;Example Expression Rule&lt;/h2&gt;
&lt;h4&gt;An example expression rule that has coverage tests and error handling tests can be found below.&lt;/h4&gt;
&lt;div style="margin-bottom:3rem;margin-top:3rem;"&gt;&lt;img style="box-shadow:3px 3px 5px rgba(0, 0, 0, 0.1);" alt=" " src="/resized-image/__size/960x720/__key/communityserver-wikis-components-files/00-00-00-00-46/expressionImage2.png" /&gt;&lt;/div&gt;
&lt;div style="margin-bottom:3rem;margin-top:3rem;"&gt;&lt;img style="box-shadow:3px 3px 5px rgba(0, 0, 0, 0.1);" alt=" " src="/resized-image/__size/960x720/__key/communityserver-wikis-components-files/00-00-00-00-46/expressionImage3.png" /&gt;&lt;/div&gt;
&lt;p&gt;&lt;b&gt;Figure &lt;/b&gt;&lt;b&gt;&lt;i&gt;N&amp;nbsp;&lt;/i&gt;&lt;/b&gt;&lt;b&gt;: Sample Expression Rule&lt;/b&gt;&lt;/p&gt;
&lt;div style="margin-bottom:3rem;margin-top:3rem;"&gt;&lt;img style="box-shadow:3px 3px 5px rgba(0, 0, 0, 0.1);" alt=" " src="/resized-image/__size/960x720/__key/communityserver-wikis-components-files/00-00-00-00-46/expressionImage4.png" /&gt;&lt;/div&gt;
&lt;p&gt;&lt;b&gt;Figure &lt;/b&gt;&lt;b&gt;&lt;i&gt;M&amp;nbsp;&lt;/i&gt;&lt;/b&gt;&lt;b&gt;: Sample Test Cases&lt;/b&gt;&lt;/p&gt;
&lt;p&gt;These are test cases a user could have set up for the rule provided in &lt;b&gt;&lt;i&gt;Figure N&lt;/i&gt;&lt;/b&gt;. The first box contains &lt;b&gt;Coverage Tests&lt;/b&gt;. They provide code coverage by testing with expected inputs and outputs. The second box contains &lt;b&gt;Error Handling Tests&lt;/b&gt;. These tests are staged with inputs that would typically result in a denominator of 0. Finally, the third box contains &lt;b&gt;Null Handling Tests&lt;/b&gt;. This is another specific type of error handling tests. They are used to verify that our rule can properly handle null inputs. Note that more than one was required for this rule.&lt;/p&gt;
&lt;h2 id="regression_testing_with_test_cases"&gt;Regression Testing with Test Cases&lt;/h2&gt;
&lt;p&gt;Test cases make it easier and faster to regression test. Before making a change to an existing expression rule, run all existing test cases within the rule and resolve any that have failed. After making the change, add coverage and error handling test cases to test the change. Finally, run all test cases to ensure the update didn&amp;rsquo;t break any existing cases.&lt;/p&gt;
&lt;p&gt;Before a deployment, run the Automated Rules Testing Application (ART) in the target environment (non-production) to ensure all test cases work as expected before the deployment. If any rules do not work, resolve the issues in the lower environment prior to the deployment. After the deployment, re-run ART in the target environment to ensure all new and old test cases work as expected.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Note: These examples are not all-encompassing. Best judgement should be used to determine what cases are required.&lt;/p&gt;
&lt;/div&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;
</description></item><item><title>How to Create Expression Rule Test Cases</title><link>https://community.appian.com/success/w/guide/3342/how-to-create-expression-rule-test-cases/revision/8</link><pubDate>Tue, 31 Oct 2023 15:06:01 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:035ef30d-5bb9-47d1-85a5-ea78a8f96c19</guid><dc:creator>joel.larin</dc:creator><comments>https://community.appian.com/success/w/guide/3342/how-to-create-expression-rule-test-cases#comments</comments><description>Revision 8 posted to Guide by joel.larin on 10/31/2023 3:06:01 PM&lt;br /&gt;
&lt;div style="margin:8px 16% 8px 8%;"&gt;
&lt;p&gt;&lt;a href="https://docs.appian.com/suite/help/latest/Expression_Rules.html#test-cases"&gt;Expression rule test cases&lt;/a&gt; enable unit testing with minimal overhead by reducing the time required to test while increasing code quality. Because expression rules have a wide variety of uses, creating meaningful test cases will speed up unit, regression, and exploratory testing. Use the following guidelines to create test cases for your expression rules that will result in greater code coverage for your application. The first section provides guidelines for creating useful test cases, and the following sections explain types of expression rule test cases in greater detail with Appian examples.&lt;/p&gt;
&lt;h2 id="test_case_creation_guidelines"&gt;Test Case Creation Guidelines&lt;/h2&gt;
&lt;p&gt;The following guidelines apply to expression rules which output a value:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Create test cases from the start of application development to aid regression testing.&amp;nbsp;&lt;/li&gt;
&lt;li&gt;If an expression rule calls another expression rule, do not duplicate test cases already created in the child within the parent rule. The parent rule should contain test cases that test any logic within the parent rule itself and should assume the child has sufficient test cases.&lt;/li&gt;
&lt;li&gt;When possible, break down large expressions to individual rules so that it is easier to ensure test coverage with expression rule test cases&lt;/li&gt;
&lt;li&gt;When expression rule test cases are evaluated, the expression is evaluated first, followed by the assertion within the test case. Avoid the use of now() in test case assertions, as this can trigger false negatives due to the dateTime type evaluating the values down to the millisecond. Instead, check whether the field is not blank.&lt;/li&gt;
&lt;li&gt;Use test!output to assert the output equals what you would expect.&lt;/li&gt;
&lt;li&gt;Use &lt;a href="/w/guide/3339/exploratory-testing"&gt;Exploratory Testing&lt;/a&gt; to identify edge cases for which to create test cases.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id="types_of_test_cases"&gt;Types of Test Cases&lt;/h2&gt;
&lt;p&gt;When creating test cases, consider the two types of test cases: &lt;b&gt;coverage tests&lt;/b&gt; and &lt;b&gt;error handling&lt;/b&gt; tests. Every expression rule should always have at least one of each kind of test case.&lt;/p&gt;
&lt;table&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;p&gt;&lt;b&gt;Test Type&lt;/b&gt;&lt;/p&gt;
&lt;/td&gt;
&lt;td&gt;
&lt;p&gt;&lt;b&gt;Description&lt;/b&gt;&lt;/p&gt;
&lt;/td&gt;
&lt;td&gt;
&lt;p&gt;&lt;b&gt;Implementation&lt;/b&gt;&lt;/p&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;p&gt;Coverage&lt;/p&gt;
&lt;/td&gt;
&lt;td&gt;
&lt;p&gt;A coverage test ensures the rule inputs result in the intended output. In other words, an area of the rule has been sufficiently &amp;ldquo;covered&amp;rdquo; via a test case.&lt;/p&gt;
&lt;/td&gt;
&lt;td&gt;
&lt;p&gt;Set inputs to expected values.&amp;nbsp;&lt;/p&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;p&gt;Error Handling&lt;/p&gt;
&lt;/td&gt;
&lt;td&gt;
&lt;p&gt;An error handling test ensures the expression rule has proper error handling.&lt;/p&gt;
&lt;/td&gt;
&lt;td&gt;
&lt;p&gt;Set inputs to values that would typically break the rule.&lt;/p&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;h2 id="creating_coverage_tests"&gt;Creating Coverage Tests&lt;/h2&gt;
&lt;h3&gt;Use the diagram below to determine which test cases are required and how to set assertions.&lt;/h3&gt;
&lt;div style="margin-bottom:3rem;margin-top:3rem;"&gt;&lt;img style="box-shadow:3px 3px 5px rgba(0, 0, 0, 0.1);" alt=" " src="/resized-image/__size/640x480/__key/communityserver-wikis-components-files/00-00-00-00-46/expressionRuleFlow.jpg" /&gt;&lt;/div&gt;
&lt;h3 id="coverage_test_case_examples"&gt;Coverage Test Case Examples&lt;/h3&gt;
&lt;h3&gt;Limited Number of Outcomes&lt;/h3&gt;
&lt;p&gt;If your expression rule has a limited number of outcomes, use the below examples to guide your test case creation. Use test!output to assert that the output is equal to the value you expect. Each outcome should have a test case and corresponding assertion.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;b&gt;Nested if()s&lt;/b&gt;: Create 1 test case per possible condition&lt;/li&gt;
&lt;li&gt;&lt;b&gt;Choose()&lt;/b&gt;: Create 1 test case per key&lt;/li&gt;
&lt;li&gt;&lt;b&gt;Mathematical Comparisons&lt;/b&gt;: Create 1 test case per possible comparison&amp;nbsp;
&lt;ul&gt;
&lt;li&gt;For example, for a &lt;i&gt;greater than&lt;/i&gt; comparison, you must have 3 cases covering when the input is less than, equal to, or greater than the comparative value&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;Unlimited Number of Outcomes&lt;/h3&gt;
&lt;p&gt;If your expression rule has an unlimited number of outcomes, use the below examples to guide your test case creation. Use test!output where it makes sense to ensure the output is equal to the expected value.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;b&gt;Calculations&lt;/b&gt;: Based on the calculation being run, identify inputs that will cover groupings of possible outcomes. The asserted output should be calculated outside of Appian and then asserted within the case.
&lt;ul&gt;
&lt;li&gt;For example, if you have a rule that is executing the following calculation: &lt;i&gt;A-B&lt;/i&gt;, with integers &lt;i&gt;A&lt;/i&gt; and &lt;i&gt;B&lt;/i&gt;, test cases should cover the following scenarios as they all would reveal something different about the calculation:
&lt;ul&gt;
&lt;li&gt;A&amp;gt;B (output is positive)&lt;/li&gt;
&lt;li&gt;A&amp;lt;B (output is negative)&lt;/li&gt;
&lt;li&gt;A=B (output is 0)&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;ul&gt;
&lt;li&gt;&lt;b&gt;Integrations: Expression Rule Test Cases can be used to test integration connectivity prior to a deployment. Create an expression rule that calls the integration and a test case that passes in data to populate the request. Set the assertion to &amp;ldquo;expression evaluates to true&amp;rdquo;. The expression should check that the &amp;ldquo;success&amp;rdquo; output of the integration = true. Add these expression rules to an app that is deployed prior to your business application.&lt;/b&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Date Times&lt;/strong&gt;:&amp;nbsp;Create test cases which cover all groupings of expected outcomes, including all known edge cases. Assert that the output is correct for each test case.&amp;nbsp;
&lt;ul&gt;
&lt;li&gt;For example, if a rule checks whether a date is a work day (calisworkday(datetime)), create test cases with the following inputs to test the possible outcomes. Use the value in parenthesis to assert that test!output is the correct value:
&lt;ul&gt;
&lt;li&gt;A work day (true)&lt;/li&gt;
&lt;li&gt;A weekend day (false)&lt;/li&gt;
&lt;li&gt;A holiday (false)&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;ul&gt;
&lt;li&gt;Consider test cases that go &amp;ldquo;stale&amp;rdquo; (rules where the output depends on whether inputs are in the past, future, etc). Avoid using hard coded dates and instead, use the appropriate Appian date and time functions (now(), today(), etc.) to ensure that test inputs will last for the lifetime of the application. As mentioned previously, do not use now() in test case assertions.&lt;/li&gt;
&lt;li&gt;If the rule contains calculations on dates in particular timezones, use the gmt() and local() functions to enforce a timezone and assert the correct output for that timezone.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;b&gt;Type Constructors&lt;/b&gt;:&amp;nbsp;Test cases are only necessary to test any logic within the rule that is outside of the constructor itself. &amp;ldquo;Assertion expression evaluates to true&amp;rdquo; is typically useful for these types of test cases.
&lt;ul&gt;
&lt;li&gt;If the rule takes a raw set of data and only casts items that meet specific criteria, a test case can be created in which you validate that all items in the output meet that criteria.&lt;/li&gt;
&lt;li&gt;If the rule casts individual fields from a rule input to a new data type, create a test case that asserts that each field equals what is expected by using test!output.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id="creating_error_handling_tests"&gt;Creating Error Handling Tests&lt;/h2&gt;
&lt;p&gt;Error handling test cases should be created based on the functions and inputs of the rule. &lt;b&gt;All &lt;/b&gt;rules should have null handling test cases (unless already covered by a parent rule), while other error handling scenarios should be determined at the Designer&amp;rsquo;s discretion. All error handling cases should have the test output match an asserted output.&lt;/p&gt;
&lt;h2 id="error_handling_test_case_examples"&gt;Error Handling Test Case Examples&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;&lt;b&gt;Null Handling: Set one, some, or all rule inputs to null to ensure the rule executes properly and outputs an expected value. In many cases, more than one null handling test case may be necessary.&lt;/b&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;div style="margin-bottom:3rem;margin-top:3rem;"&gt;&lt;img style="box-shadow:3px 3px 5px rgba(0, 0, 0, 0.1);" alt=" " src="/resized-image/__size/960x720/__key/communityserver-wikis-components-files/00-00-00-00-46/expressionImage1.png" /&gt;&lt;/div&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Invalid Mathematical Expressions&lt;/strong&gt;: In rules that execute a calculation, provide inputs that produce an invalid calculation, such as a denominator of zero. Ensure the rule still executes properly and outputs the expected value.
&lt;ul&gt;
&lt;li&gt;For example, if your rule is calculating the square root of the difference between &lt;i&gt;A &lt;/i&gt;and &lt;i&gt;B&lt;/i&gt;, create a case in which B &amp;gt; A.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;ul&gt;
&lt;li&gt;&lt;b&gt;Functions that error given invalid inputs: If a rule uses functions that produce an expression error if the input is invalid (e.g. user/group functions, not(), etc), create a test case for each invalid input to verify that expression errors are avoided.&lt;/b&gt;
&lt;ul&gt;
&lt;li&gt;For example, if your rule has a username input, cases should be created in which a random non-username string is passed in. The rule should be coded to handle this case properly.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Date Times&lt;/strong&gt;: Create test cases with datetimes outside of what the rule expects to ensure that the rule handles them appropriately.&lt;/li&gt;
&lt;/ul&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Queries&lt;/strong&gt;:&amp;nbsp;
&lt;ul&gt;
&lt;li&gt;For queries in which data is consistent across environments, regardless of user interaction with the system (i.e. reference data), create test cases with data that will always be returned and assert that the test output matches the desired value.&lt;/li&gt;
&lt;li&gt;For queries on transactional data, expression rule test cases should not be used to validate that a particular data set is returned because data can vary based on the environment and user interaction. However, test cases can still be used in the following ways:
&lt;ul&gt;
&lt;li&gt;On all expression rules that have queries, you can create a test case which asserts that the &amp;ldquo;&lt;a href="https://docs.appian.com/suite/help/20.3/Expression_Rules.html#test-case-assertions"&gt;Test completes without errors&lt;/a&gt;&amp;rdquo; to validate &lt;b&gt;database connectivity&lt;/b&gt;.&amp;nbsp;&lt;/li&gt;
&lt;li&gt;If the query ignores null filter values, include a test case which passes in values for all possible filters and asserts that the test completes without errors to ensure that all&lt;b&gt; field names and filter configurations&lt;/b&gt; are valid.&lt;/li&gt;
&lt;li&gt;If the query does not ignore null filter values, create &lt;b&gt;null-handling&lt;/b&gt; test cases for the rule.&amp;nbsp;&lt;/li&gt;
&lt;li&gt;For all filters that are created, test cases can be used to validate that the returned results match the&lt;b&gt; filter value&lt;/b&gt; that was passed in. For example, if &amp;ldquo;true&amp;rdquo; is passed into an &amp;ldquo;isActive&amp;rdquo; filter in the query, a test case can validate that all results returned have isActive=true. For test cases like these, include appropriate null handling for when no data matches the filter criteria.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Use test cases to assert that the output is of the same &lt;b&gt;data type&lt;/b&gt; as the data entity being queried. This can be done using the &amp;ldquo;&lt;a href="https://docs.appian.com/suite/help/20.3/Expression_Rules.html#test-case-assertions"&gt;Assertion expression evaluates to true&lt;/a&gt;&amp;rdquo; assertion option, where the expression would check that the type of test!output matches the expected type using the typeof() function.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;i&gt;Note: Expression rules containing queries should only include the a!queryEntity() function. Any expressions to manipulate the data or output different values based on the query results should be done in separate expression rules, using the results of the query as a rule input. This allows flexibility to assert that the manipulation or conditional output operates correctly without relying on transaction data that can change across Appian environments.&lt;/i&gt;&lt;/p&gt;
&lt;h2 id="example_expression_rule"&gt;Example Expression Rule&lt;/h2&gt;
&lt;h4&gt;An example expression rule that has coverage tests and error handling tests can be found below.&lt;/h4&gt;
&lt;div style="margin-bottom:3rem;margin-top:3rem;"&gt;&lt;img style="box-shadow:3px 3px 5px rgba(0, 0, 0, 0.1);" alt=" " src="/resized-image/__size/960x720/__key/communityserver-wikis-components-files/00-00-00-00-46/expressionImage2.png" /&gt;&lt;/div&gt;
&lt;div style="margin-bottom:3rem;margin-top:3rem;"&gt;&lt;img style="box-shadow:3px 3px 5px rgba(0, 0, 0, 0.1);" alt=" " src="/resized-image/__size/960x720/__key/communityserver-wikis-components-files/00-00-00-00-46/expressionImage3.png" /&gt;&lt;/div&gt;
&lt;p&gt;&lt;b&gt;Figure &lt;/b&gt;&lt;b&gt;&lt;i&gt;N&amp;nbsp;&lt;/i&gt;&lt;/b&gt;&lt;b&gt;: Sample Expression Rule&lt;/b&gt;&lt;/p&gt;
&lt;div style="margin-bottom:3rem;margin-top:3rem;"&gt;&lt;img style="box-shadow:3px 3px 5px rgba(0, 0, 0, 0.1);" alt=" " src="/resized-image/__size/960x720/__key/communityserver-wikis-components-files/00-00-00-00-46/expressionImage4.png" /&gt;&lt;/div&gt;
&lt;p&gt;&lt;b&gt;Figure &lt;/b&gt;&lt;b&gt;&lt;i&gt;M&amp;nbsp;&lt;/i&gt;&lt;/b&gt;&lt;b&gt;: Sample Test Cases&lt;/b&gt;&lt;/p&gt;
&lt;p&gt;These are test cases a user could have set up for the rule provided in &lt;b&gt;&lt;i&gt;Figure N&lt;/i&gt;&lt;/b&gt;. The first box contains &lt;b&gt;Coverage Tests&lt;/b&gt;. They provide code coverage by testing with expected inputs and outputs. The second box contains &lt;b&gt;Error Handling Tests&lt;/b&gt;. These tests are staged with inputs that would typically result in a denominator of 0. Finally, the third box contains &lt;b&gt;Null Handling Tests&lt;/b&gt;. This is another specific type of error handling tests. They are used to verify that our rule can properly handle null inputs. Note that more than one was required for this rule.&lt;/p&gt;
&lt;h2 id="regression_testing_with_test_cases"&gt;Regression Testing with Test Cases&lt;/h2&gt;
&lt;p&gt;Test cases make it easier and faster to regression test. Before making a change to an existing expression rule, run all existing test cases within the rule and resolve any that have failed. After making the change, add coverage and error handling test cases to test the change. Finally, run all test cases to ensure the update didn&amp;rsquo;t break any existing cases.&lt;/p&gt;
&lt;p&gt;Before a deployment, run the Automated Rules Testing Application (ART) in the target environment (non-production) to ensure all test cases work as expected before the deployment. If any rules do not work, resolve the issues in the lower environment prior to the deployment. After the deployment, re-run ART in the target environment to ensure all new and old test cases work as expected.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Note: These examples are not all-encompassing. Best judgement should be used to determine what cases are required.&lt;/p&gt;
&lt;/div&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;
</description></item><item><title>How to Create Expression Rule Test Cases</title><link>https://community.appian.com/success/w/guide/3342/how-to-create-expression-rule-test-cases/revision/7</link><pubDate>Tue, 31 Oct 2023 15:05:24 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:035ef30d-5bb9-47d1-85a5-ea78a8f96c19</guid><dc:creator>joel.larin</dc:creator><comments>https://community.appian.com/success/w/guide/3342/how-to-create-expression-rule-test-cases#comments</comments><description>Revision 7 posted to Guide by joel.larin on 10/31/2023 3:05:24 PM&lt;br /&gt;
&lt;div style="margin:8px 16% 8px 8%;"&gt;
&lt;p&gt;&lt;a href="https://docs.appian.com/suite/help/latest/Expression_Rules.html#test-cases"&gt;Expression rule test cases&lt;/a&gt; enable unit testing with minimal overhead by reducing the time required to test while increasing code quality. Because expression rules have a wide variety of uses, creating meaningful test cases will speed up unit, regression, and exploratory testing. Use the following guidelines to create test cases for your expression rules that will result in greater code coverage for your application. The first section provides guidelines for creating useful test cases, and the following sections explain types of expression rule test cases in greater detail with Appian examples.&lt;/p&gt;
&lt;h2 id="test_case_creation_guidelines"&gt;Test Case Creation Guidelines&lt;/h2&gt;
&lt;p&gt;The following guidelines apply to expression rules which output a value:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Create test cases from the start of application development to aid regression testing.&amp;nbsp;&lt;/li&gt;
&lt;li&gt;If an expression rule calls another expression rule, do not duplicate test cases already created in the child within the parent rule. The parent rule should contain test cases that test any logic within the parent rule itself and should assume the child has sufficient test cases.&lt;/li&gt;
&lt;li&gt;When possible, break down large expressions to individual rules so that it is easier to ensure test coverage with expression rule test cases&lt;/li&gt;
&lt;li&gt;When expression rule test cases are evaluated, the expression is evaluated first, followed by the assertion within the test case. Avoid the use of now() in test case assertions, as this can trigger false negatives due to the dateTime type evaluating the values down to the millisecond. Instead, check whether the field is not blank.&lt;/li&gt;
&lt;li&gt;Use test!output to assert the output equals what you would expect.&lt;/li&gt;
&lt;li&gt;Use &lt;a href="/w/guide/3339/exploratory-testing"&gt;Exploratory Testing&lt;/a&gt; to identify edge cases for which to create test cases.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id="types_of_test_cases"&gt;Types of Test Cases&lt;/h2&gt;
&lt;p&gt;When creating test cases, consider the two types of test cases: &lt;b&gt;coverage tests&lt;/b&gt; and &lt;b&gt;error handling&lt;/b&gt; tests. Every expression rule should always have at least one of each kind of test case.&lt;/p&gt;
&lt;table&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;p&gt;&lt;b&gt;Test Type&lt;/b&gt;&lt;/p&gt;
&lt;/td&gt;
&lt;td&gt;
&lt;p&gt;&lt;b&gt;Description&lt;/b&gt;&lt;/p&gt;
&lt;/td&gt;
&lt;td&gt;
&lt;p&gt;&lt;b&gt;Implementation&lt;/b&gt;&lt;/p&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;p&gt;Coverage&lt;/p&gt;
&lt;/td&gt;
&lt;td&gt;
&lt;p&gt;A coverage test ensures the rule inputs result in the intended output. In other words, an area of the rule has been sufficiently &amp;ldquo;covered&amp;rdquo; via a test case.&lt;/p&gt;
&lt;/td&gt;
&lt;td&gt;
&lt;p&gt;Set inputs to expected values.&amp;nbsp;&lt;/p&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;p&gt;Error Handling&lt;/p&gt;
&lt;/td&gt;
&lt;td&gt;
&lt;p&gt;An error handling test ensures the expression rule has proper error handling.&lt;/p&gt;
&lt;/td&gt;
&lt;td&gt;
&lt;p&gt;Set inputs to values that would typically break the rule.&lt;/p&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;h2 id="creating_coverage_tests"&gt;Creating Coverage Tests&lt;/h2&gt;
&lt;h3&gt;Use the diagram below to determine which test cases are required and how to set assertions.&lt;/h3&gt;
&lt;div style="margin-bottom:3rem;margin-top:3rem;"&gt;&lt;img style="box-shadow:3px 3px 5px rgba(0, 0, 0, 0.1);" alt=" " src="/resized-image/__size/640x480/__key/communityserver-wikis-components-files/00-00-00-00-46/expressionRuleFlow.jpg" /&gt;&lt;/div&gt;
&lt;h2 id="coverage_test_case_examples"&gt;Coverage Test Case Examples&lt;/h2&gt;
&lt;h3&gt;Limited Number of Outcomes&lt;/h3&gt;
&lt;p&gt;If your expression rule has a limited number of outcomes, use the below examples to guide your test case creation. Use test!output to assert that the output is equal to the value you expect. Each outcome should have a test case and corresponding assertion.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;b&gt;Nested if()s&lt;/b&gt;: Create 1 test case per possible condition&lt;/li&gt;
&lt;li&gt;&lt;b&gt;Choose()&lt;/b&gt;: Create 1 test case per key&lt;/li&gt;
&lt;li&gt;&lt;b&gt;Mathematical Comparisons&lt;/b&gt;: Create 1 test case per possible comparison&amp;nbsp;
&lt;ul&gt;
&lt;li&gt;For example, for a &lt;i&gt;greater than&lt;/i&gt; comparison, you must have 3 cases covering when the input is less than, equal to, or greater than the comparative value&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;Unlimited Number of Outcomes&lt;/h3&gt;
&lt;p&gt;If your expression rule has an unlimited number of outcomes, use the below examples to guide your test case creation. Use test!output where it makes sense to ensure the output is equal to the expected value.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;b&gt;Calculations&lt;/b&gt;: Based on the calculation being run, identify inputs that will cover groupings of possible outcomes. The asserted output should be calculated outside of Appian and then asserted within the case.
&lt;ul&gt;
&lt;li&gt;For example, if you have a rule that is executing the following calculation: &lt;i&gt;A-B&lt;/i&gt;, with integers &lt;i&gt;A&lt;/i&gt; and &lt;i&gt;B&lt;/i&gt;, test cases should cover the following scenarios as they all would reveal something different about the calculation:
&lt;ul&gt;
&lt;li&gt;A&amp;gt;B (output is positive)&lt;/li&gt;
&lt;li&gt;A&amp;lt;B (output is negative)&lt;/li&gt;
&lt;li&gt;A=B (output is 0)&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;ul&gt;
&lt;li&gt;&lt;b&gt;Integrations: Expression Rule Test Cases can be used to test integration connectivity prior to a deployment. Create an expression rule that calls the integration and a test case that passes in data to populate the request. Set the assertion to &amp;ldquo;expression evaluates to true&amp;rdquo;. The expression should check that the &amp;ldquo;success&amp;rdquo; output of the integration = true. Add these expression rules to an app that is deployed prior to your business application.&lt;/b&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Date Times&lt;/strong&gt;:&amp;nbsp;Create test cases which cover all groupings of expected outcomes, including all known edge cases. Assert that the output is correct for each test case.&amp;nbsp;
&lt;ul&gt;
&lt;li&gt;For example, if a rule checks whether a date is a work day (calisworkday(datetime)), create test cases with the following inputs to test the possible outcomes. Use the value in parenthesis to assert that test!output is the correct value:
&lt;ul&gt;
&lt;li&gt;A work day (true)&lt;/li&gt;
&lt;li&gt;A weekend day (false)&lt;/li&gt;
&lt;li&gt;A holiday (false)&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;ul&gt;
&lt;li&gt;Consider test cases that go &amp;ldquo;stale&amp;rdquo; (rules where the output depends on whether inputs are in the past, future, etc). Avoid using hard coded dates and instead, use the appropriate Appian date and time functions (now(), today(), etc.) to ensure that test inputs will last for the lifetime of the application. As mentioned previously, do not use now() in test case assertions.&lt;/li&gt;
&lt;li&gt;If the rule contains calculations on dates in particular timezones, use the gmt() and local() functions to enforce a timezone and assert the correct output for that timezone.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;b&gt;Type Constructors&lt;/b&gt;:&amp;nbsp;Test cases are only necessary to test any logic within the rule that is outside of the constructor itself. &amp;ldquo;Assertion expression evaluates to true&amp;rdquo; is typically useful for these types of test cases.
&lt;ul&gt;
&lt;li&gt;If the rule takes a raw set of data and only casts items that meet specific criteria, a test case can be created in which you validate that all items in the output meet that criteria.&lt;/li&gt;
&lt;li&gt;If the rule casts individual fields from a rule input to a new data type, create a test case that asserts that each field equals what is expected by using test!output.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id="creating_error_handling_tests"&gt;Creating Error Handling Tests&lt;/h2&gt;
&lt;p&gt;Error handling test cases should be created based on the functions and inputs of the rule. &lt;b&gt;All &lt;/b&gt;rules should have null handling test cases (unless already covered by a parent rule), while other error handling scenarios should be determined at the Designer&amp;rsquo;s discretion. All error handling cases should have the test output match an asserted output.&lt;/p&gt;
&lt;h2 id="error_handling_test_case_examples"&gt;Error Handling Test Case Examples&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;&lt;b&gt;Null Handling: Set one, some, or all rule inputs to null to ensure the rule executes properly and outputs an expected value. In many cases, more than one null handling test case may be necessary.&lt;/b&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;div style="margin-bottom:3rem;margin-top:3rem;"&gt;&lt;img style="box-shadow:3px 3px 5px rgba(0, 0, 0, 0.1);" alt=" " src="/resized-image/__size/960x720/__key/communityserver-wikis-components-files/00-00-00-00-46/expressionImage1.png" /&gt;&lt;/div&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Invalid Mathematical Expressions&lt;/strong&gt;: In rules that execute a calculation, provide inputs that produce an invalid calculation, such as a denominator of zero. Ensure the rule still executes properly and outputs the expected value.
&lt;ul&gt;
&lt;li&gt;For example, if your rule is calculating the square root of the difference between &lt;i&gt;A &lt;/i&gt;and &lt;i&gt;B&lt;/i&gt;, create a case in which B &amp;gt; A.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;ul&gt;
&lt;li&gt;&lt;b&gt;Functions that error given invalid inputs: If a rule uses functions that produce an expression error if the input is invalid (e.g. user/group functions, not(), etc), create a test case for each invalid input to verify that expression errors are avoided.&lt;/b&gt;
&lt;ul&gt;
&lt;li&gt;For example, if your rule has a username input, cases should be created in which a random non-username string is passed in. The rule should be coded to handle this case properly.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Date Times&lt;/strong&gt;: Create test cases with datetimes outside of what the rule expects to ensure that the rule handles them appropriately.&lt;/li&gt;
&lt;/ul&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Queries&lt;/strong&gt;:&amp;nbsp;
&lt;ul&gt;
&lt;li&gt;For queries in which data is consistent across environments, regardless of user interaction with the system (i.e. reference data), create test cases with data that will always be returned and assert that the test output matches the desired value.&lt;/li&gt;
&lt;li&gt;For queries on transactional data, expression rule test cases should not be used to validate that a particular data set is returned because data can vary based on the environment and user interaction. However, test cases can still be used in the following ways:
&lt;ul&gt;
&lt;li&gt;On all expression rules that have queries, you can create a test case which asserts that the &amp;ldquo;&lt;a href="https://docs.appian.com/suite/help/20.3/Expression_Rules.html#test-case-assertions"&gt;Test completes without errors&lt;/a&gt;&amp;rdquo; to validate &lt;b&gt;database connectivity&lt;/b&gt;.&amp;nbsp;&lt;/li&gt;
&lt;li&gt;If the query ignores null filter values, include a test case which passes in values for all possible filters and asserts that the test completes without errors to ensure that all&lt;b&gt; field names and filter configurations&lt;/b&gt; are valid.&lt;/li&gt;
&lt;li&gt;If the query does not ignore null filter values, create &lt;b&gt;null-handling&lt;/b&gt; test cases for the rule.&amp;nbsp;&lt;/li&gt;
&lt;li&gt;For all filters that are created, test cases can be used to validate that the returned results match the&lt;b&gt; filter value&lt;/b&gt; that was passed in. For example, if &amp;ldquo;true&amp;rdquo; is passed into an &amp;ldquo;isActive&amp;rdquo; filter in the query, a test case can validate that all results returned have isActive=true. For test cases like these, include appropriate null handling for when no data matches the filter criteria.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Use test cases to assert that the output is of the same &lt;b&gt;data type&lt;/b&gt; as the data entity being queried. This can be done using the &amp;ldquo;&lt;a href="https://docs.appian.com/suite/help/20.3/Expression_Rules.html#test-case-assertions"&gt;Assertion expression evaluates to true&lt;/a&gt;&amp;rdquo; assertion option, where the expression would check that the type of test!output matches the expected type using the typeof() function.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;i&gt;Note: Expression rules containing queries should only include the a!queryEntity() function. Any expressions to manipulate the data or output different values based on the query results should be done in separate expression rules, using the results of the query as a rule input. This allows flexibility to assert that the manipulation or conditional output operates correctly without relying on transaction data that can change across Appian environments.&lt;/i&gt;&lt;/p&gt;
&lt;h2 id="example_expression_rule"&gt;Example Expression Rule&lt;/h2&gt;
&lt;h4&gt;An example expression rule that has coverage tests and error handling tests can be found below.&lt;/h4&gt;
&lt;div style="margin-bottom:3rem;margin-top:3rem;"&gt;&lt;img style="box-shadow:3px 3px 5px rgba(0, 0, 0, 0.1);" alt=" " src="/resized-image/__size/960x720/__key/communityserver-wikis-components-files/00-00-00-00-46/expressionImage2.png" /&gt;&lt;/div&gt;
&lt;div style="margin-bottom:3rem;margin-top:3rem;"&gt;&lt;img style="box-shadow:3px 3px 5px rgba(0, 0, 0, 0.1);" alt=" " src="/resized-image/__size/960x720/__key/communityserver-wikis-components-files/00-00-00-00-46/expressionImage3.png" /&gt;&lt;/div&gt;
&lt;p&gt;&lt;b&gt;Figure &lt;/b&gt;&lt;b&gt;&lt;i&gt;N&amp;nbsp;&lt;/i&gt;&lt;/b&gt;&lt;b&gt;: Sample Expression Rule&lt;/b&gt;&lt;/p&gt;
&lt;div style="margin-bottom:3rem;margin-top:3rem;"&gt;&lt;img style="box-shadow:3px 3px 5px rgba(0, 0, 0, 0.1);" alt=" " src="/resized-image/__size/960x720/__key/communityserver-wikis-components-files/00-00-00-00-46/expressionImage4.png" /&gt;&lt;/div&gt;
&lt;p&gt;&lt;b&gt;Figure &lt;/b&gt;&lt;b&gt;&lt;i&gt;M&amp;nbsp;&lt;/i&gt;&lt;/b&gt;&lt;b&gt;: Sample Test Cases&lt;/b&gt;&lt;/p&gt;
&lt;p&gt;These are test cases a user could have set up for the rule provided in &lt;b&gt;&lt;i&gt;Figure N&lt;/i&gt;&lt;/b&gt;. The first box contains &lt;b&gt;Coverage Tests&lt;/b&gt;. They provide code coverage by testing with expected inputs and outputs. The second box contains &lt;b&gt;Error Handling Tests&lt;/b&gt;. These tests are staged with inputs that would typically result in a denominator of 0. Finally, the third box contains &lt;b&gt;Null Handling Tests&lt;/b&gt;. This is another specific type of error handling tests. They are used to verify that our rule can properly handle null inputs. Note that more than one was required for this rule.&lt;/p&gt;
&lt;h2 id="regression_testing_with_test_cases"&gt;Regression Testing with Test Cases&lt;/h2&gt;
&lt;p&gt;Test cases make it easier and faster to regression test. Before making a change to an existing expression rule, run all existing test cases within the rule and resolve any that have failed. After making the change, add coverage and error handling test cases to test the change. Finally, run all test cases to ensure the update didn&amp;rsquo;t break any existing cases.&lt;/p&gt;
&lt;p&gt;Before a deployment, run the Automated Rules Testing Application (ART) in the target environment (non-production) to ensure all test cases work as expected before the deployment. If any rules do not work, resolve the issues in the lower environment prior to the deployment. After the deployment, re-run ART in the target environment to ensure all new and old test cases work as expected.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Note: These examples are not all-encompassing. Best judgement should be used to determine what cases are required.&lt;/p&gt;
&lt;/div&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;
</description></item><item><title>How to Create Expression Rule Test Cases</title><link>https://community.appian.com/success/w/guide/3342/how-to-create-expression-rule-test-cases/revision/6</link><pubDate>Tue, 31 Oct 2023 15:04:21 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:035ef30d-5bb9-47d1-85a5-ea78a8f96c19</guid><dc:creator>joel.larin</dc:creator><comments>https://community.appian.com/success/w/guide/3342/how-to-create-expression-rule-test-cases#comments</comments><description>Revision 6 posted to Guide by joel.larin on 10/31/2023 3:04:21 PM&lt;br /&gt;
&lt;div style="margin:8px 16% 8px 8%;"&gt;
&lt;h3 id="introduction"&gt;Introduction&lt;/h3&gt;
&lt;p&gt;&lt;a href="https://docs.appian.com/suite/help/latest/Expression_Rules.html#test-cases"&gt;Expression rule test cases&lt;/a&gt; enable unit testing with minimal overhead by reducing the time required to test while increasing code quality. Because expression rules have a wide variety of uses, creating meaningful test cases will speed up unit, regression, and exploratory testing. Use the following guidelines to create test cases for your expression rules that will result in greater code coverage for your application. The first section provides guidelines for creating useful test cases, and the following sections explain types of expression rule test cases in greater detail with Appian examples.&lt;/p&gt;
&lt;h2 id="test_case_creation_guidelines"&gt;Test Case Creation Guidelines&lt;/h2&gt;
&lt;p&gt;The following guidelines apply to expression rules which output a value:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Create test cases from the start of application development to aid regression testing.&amp;nbsp;&lt;/li&gt;
&lt;li&gt;If an expression rule calls another expression rule, do not duplicate test cases already created in the child within the parent rule. The parent rule should contain test cases that test any logic within the parent rule itself and should assume the child has sufficient test cases.&lt;/li&gt;
&lt;li&gt;When possible, break down large expressions to individual rules so that it is easier to ensure test coverage with expression rule test cases&lt;/li&gt;
&lt;li&gt;When expression rule test cases are evaluated, the expression is evaluated first, followed by the assertion within the test case. Avoid the use of now() in test case assertions, as this can trigger false negatives due to the dateTime type evaluating the values down to the millisecond. Instead, check whether the field is not blank.&lt;/li&gt;
&lt;li&gt;Use test!output to assert the output equals what you would expect.&lt;/li&gt;
&lt;li&gt;Use &lt;a href="/w/guide/3339/exploratory-testing"&gt;Exploratory Testing&lt;/a&gt; to identify edge cases for which to create test cases.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id="types_of_test_cases"&gt;Types of Test Cases&lt;/h2&gt;
&lt;p&gt;When creating test cases, consider the two types of test cases: &lt;b&gt;coverage tests&lt;/b&gt; and &lt;b&gt;error handling&lt;/b&gt; tests. Every expression rule should always have at least one of each kind of test case.&lt;/p&gt;
&lt;table&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;p&gt;&lt;b&gt;Test Type&lt;/b&gt;&lt;/p&gt;
&lt;/td&gt;
&lt;td&gt;
&lt;p&gt;&lt;b&gt;Description&lt;/b&gt;&lt;/p&gt;
&lt;/td&gt;
&lt;td&gt;
&lt;p&gt;&lt;b&gt;Implementation&lt;/b&gt;&lt;/p&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;p&gt;Coverage&lt;/p&gt;
&lt;/td&gt;
&lt;td&gt;
&lt;p&gt;A coverage test ensures the rule inputs result in the intended output. In other words, an area of the rule has been sufficiently &amp;ldquo;covered&amp;rdquo; via a test case.&lt;/p&gt;
&lt;/td&gt;
&lt;td&gt;
&lt;p&gt;Set inputs to expected values.&amp;nbsp;&lt;/p&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;p&gt;Error Handling&lt;/p&gt;
&lt;/td&gt;
&lt;td&gt;
&lt;p&gt;An error handling test ensures the expression rule has proper error handling.&lt;/p&gt;
&lt;/td&gt;
&lt;td&gt;
&lt;p&gt;Set inputs to values that would typically break the rule.&lt;/p&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;h2 id="creating_coverage_tests"&gt;Creating Coverage Tests&lt;/h2&gt;
&lt;h3&gt;Use the diagram below to determine which test cases are required and how to set assertions.&lt;/h3&gt;
&lt;div style="margin-bottom:3rem;margin-top:3rem;"&gt;&lt;img style="box-shadow:3px 3px 5px rgba(0, 0, 0, 0.1);" alt=" " src="/resized-image/__size/640x480/__key/communityserver-wikis-components-files/00-00-00-00-46/expressionRuleFlow.jpg" /&gt;&lt;/div&gt;
&lt;h2 id="coverage_test_case_examples*"&gt;Coverage Test Case Examples*&lt;/h2&gt;
&lt;h3&gt;Limited Number of Outcomes&lt;/h3&gt;
&lt;p&gt;If your expression rule has a limited number of outcomes, use the below examples to guide your test case creation. Use test!output to assert that the output is equal to the value you expect. Each outcome should have a test case and corresponding assertion.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;b&gt;Nested if()s&lt;/b&gt;: Create 1 test case per possible condition&lt;/li&gt;
&lt;li&gt;&lt;b&gt;Choose()&lt;/b&gt;: Create 1 test case per key&lt;/li&gt;
&lt;li&gt;&lt;b&gt;Mathematical Comparisons&lt;/b&gt;: Create 1 test case per possible comparison&amp;nbsp;
&lt;ul&gt;
&lt;li&gt;For example, for a &lt;i&gt;greater than&lt;/i&gt; comparison, you must have 3 cases covering when the input is less than, equal to, or greater than the comparative value&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;Unlimited Number of Outcomes&lt;/h3&gt;
&lt;p&gt;If your expression rule has an unlimited number of outcomes, use the below examples to guide your test case creation. Use test!output where it makes sense to ensure the output is equal to the expected value.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;b&gt;Calculations&lt;/b&gt;: Based on the calculation being run, identify inputs that will cover groupings of possible outcomes. The asserted output should be calculated outside of Appian and then asserted within the case.
&lt;ul&gt;
&lt;li&gt;For example, if you have a rule that is executing the following calculation: &lt;i&gt;A-B&lt;/i&gt;, with integers &lt;i&gt;A&lt;/i&gt; and &lt;i&gt;B&lt;/i&gt;, test cases should cover the following scenarios as they all would reveal something different about the calculation:
&lt;ul&gt;
&lt;li&gt;A&amp;gt;B (output is positive)&lt;/li&gt;
&lt;li&gt;A&amp;lt;B (output is negative)&lt;/li&gt;
&lt;li&gt;A=B (output is 0)&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;ul&gt;
&lt;li&gt;&lt;b&gt;Integrations: Expression Rule Test Cases can be used to test integration connectivity prior to a deployment. Create an expression rule that calls the integration and a test case that passes in data to populate the request. Set the assertion to &amp;ldquo;expression evaluates to true&amp;rdquo;. The expression should check that the &amp;ldquo;success&amp;rdquo; output of the integration = true. Add these expression rules to an app that is deployed prior to your business application.&lt;/b&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Date Times&lt;/strong&gt;:&amp;nbsp;Create test cases which cover all groupings of expected outcomes, including all known edge cases. Assert that the output is correct for each test case.&amp;nbsp;
&lt;ul&gt;
&lt;li&gt;For example, if a rule checks whether a date is a work day (calisworkday(datetime)), create test cases with the following inputs to test the possible outcomes. Use the value in parenthesis to assert that test!output is the correct value:
&lt;ul&gt;
&lt;li&gt;A work day (true)&lt;/li&gt;
&lt;li&gt;A weekend day (false)&lt;/li&gt;
&lt;li&gt;A holiday (false)&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;ul&gt;
&lt;li&gt;Consider test cases that go &amp;ldquo;stale&amp;rdquo; (rules where the output depends on whether inputs are in the past, future, etc). Avoid using hard coded dates and instead, use the appropriate Appian date and time functions (now(), today(), etc.) to ensure that test inputs will last for the lifetime of the application. As mentioned previously, do not use now() in test case assertions.&lt;/li&gt;
&lt;li&gt;If the rule contains calculations on dates in particular timezones, use the gmt() and local() functions to enforce a timezone and assert the correct output for that timezone.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;b&gt;Type Constructors&lt;/b&gt;:&amp;nbsp;Test cases are only necessary to test any logic within the rule that is outside of the constructor itself. &amp;ldquo;Assertion expression evaluates to true&amp;rdquo; is typically useful for these types of test cases.
&lt;ul&gt;
&lt;li&gt;If the rule takes a raw set of data and only casts items that meet specific criteria, a test case can be created in which you validate that all items in the output meet that criteria.&lt;/li&gt;
&lt;li&gt;If the rule casts individual fields from a rule input to a new data type, create a test case that asserts that each field equals what is expected by using test!output.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id="creating_error_handling_tests"&gt;Creating Error Handling Tests&lt;/h2&gt;
&lt;p&gt;Error handling test cases should be created based on the functions and inputs of the rule. &lt;b&gt;All &lt;/b&gt;rules should have null handling test cases (unless already covered by a parent rule), while other error handling scenarios should be determined at the Designer&amp;rsquo;s discretion. All error handling cases should have the test output match an asserted output.&lt;/p&gt;
&lt;h2 id="error_handling_test_case_examples*"&gt;Error Handling Test Case Examples*&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;&lt;b&gt;Null Handling: Set one, some, or all rule inputs to null to ensure the rule executes properly and outputs an expected value. In many cases, more than one null handling test case may be necessary.&lt;/b&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;div style="margin-bottom:3rem;margin-top:3rem;"&gt;&lt;img style="box-shadow:3px 3px 5px rgba(0, 0, 0, 0.1);" alt=" " src="/resized-image/__size/960x720/__key/communityserver-wikis-components-files/00-00-00-00-46/expressionImage1.png" /&gt;&lt;/div&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Invalid Mathematical Expressions&lt;/strong&gt;: In rules that execute a calculation, provide inputs that produce an invalid calculation, such as a denominator of zero. Ensure the rule still executes properly and outputs the expected value.
&lt;ul&gt;
&lt;li&gt;For example, if your rule is calculating the square root of the difference between &lt;i&gt;A &lt;/i&gt;and &lt;i&gt;B&lt;/i&gt;, create a case in which B &amp;gt; A.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;ul&gt;
&lt;li&gt;&lt;b&gt;Functions that error given invalid inputs: If a rule uses functions that produce an expression error if the input is invalid (e.g. user/group functions, not(), etc), create a test case for each invalid input to verify that expression errors are avoided.&lt;/b&gt;
&lt;ul&gt;
&lt;li&gt;For example, if your rule has a username input, cases should be created in which a random non-username string is passed in. The rule should be coded to handle this case properly.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Date Times&lt;/strong&gt;: Create test cases with datetimes outside of what the rule expects to ensure that the rule handles them appropriately.&lt;/li&gt;
&lt;/ul&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Queries&lt;/strong&gt;:&amp;nbsp;
&lt;ul&gt;
&lt;li&gt;For queries in which data is consistent across environments, regardless of user interaction with the system (i.e. reference data), create test cases with data that will always be returned and assert that the test output matches the desired value.&lt;/li&gt;
&lt;li&gt;For queries on transactional data, expression rule test cases should not be used to validate that a particular data set is returned because data can vary based on the environment and user interaction. However, test cases can still be used in the following ways:
&lt;ul&gt;
&lt;li&gt;On all expression rules that have queries, you can create a test case which asserts that the &amp;ldquo;&lt;a href="https://docs.appian.com/suite/help/20.3/Expression_Rules.html#test-case-assertions"&gt;Test completes without errors&lt;/a&gt;&amp;rdquo; to validate &lt;b&gt;database connectivity&lt;/b&gt;.&amp;nbsp;&lt;/li&gt;
&lt;li&gt;If the query ignores null filter values, include a test case which passes in values for all possible filters and asserts that the test completes without errors to ensure that all&lt;b&gt; field names and filter configurations&lt;/b&gt; are valid.&lt;/li&gt;
&lt;li&gt;If the query does not ignore null filter values, create &lt;b&gt;null-handling&lt;/b&gt; test cases for the rule.&amp;nbsp;&lt;/li&gt;
&lt;li&gt;For all filters that are created, test cases can be used to validate that the returned results match the&lt;b&gt; filter value&lt;/b&gt; that was passed in. For example, if &amp;ldquo;true&amp;rdquo; is passed into an &amp;ldquo;isActive&amp;rdquo; filter in the query, a test case can validate that all results returned have isActive=true. For test cases like these, include appropriate null handling for when no data matches the filter criteria.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Use test cases to assert that the output is of the same &lt;b&gt;data type&lt;/b&gt; as the data entity being queried. This can be done using the &amp;ldquo;&lt;a href="https://docs.appian.com/suite/help/20.3/Expression_Rules.html#test-case-assertions"&gt;Assertion expression evaluates to true&lt;/a&gt;&amp;rdquo; assertion option, where the expression would check that the type of test!output matches the expected type using the typeof() function.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;i&gt;Note: Expression rules containing queries should only include the a!queryEntity() function. Any expressions to manipulate the data or output different values based on the query results should be done in separate expression rules, using the results of the query as a rule input. This allows flexibility to assert that the manipulation or conditional output operates correctly without relying on transaction data that can change across Appian environments.&lt;/i&gt;&lt;/p&gt;
&lt;h2 id="example_expression_rule"&gt;Example Expression Rule&lt;/h2&gt;
&lt;h4&gt;An example expression rule that has coverage tests and error handling tests can be found below.&lt;/h4&gt;
&lt;div style="margin-bottom:3rem;margin-top:3rem;"&gt;&lt;img style="box-shadow:3px 3px 5px rgba(0, 0, 0, 0.1);" alt=" " src="/resized-image/__size/960x720/__key/communityserver-wikis-components-files/00-00-00-00-46/expressionImage2.png" /&gt;&lt;/div&gt;
&lt;div style="margin-bottom:3rem;margin-top:3rem;"&gt;&lt;img style="box-shadow:3px 3px 5px rgba(0, 0, 0, 0.1);" alt=" " src="/resized-image/__size/960x720/__key/communityserver-wikis-components-files/00-00-00-00-46/expressionImage3.png" /&gt;&lt;/div&gt;
&lt;p&gt;&lt;b&gt;Figure &lt;/b&gt;&lt;b&gt;&lt;i&gt;N&amp;nbsp;&lt;/i&gt;&lt;/b&gt;&lt;b&gt;: Sample Expression Rule&lt;/b&gt;&lt;/p&gt;
&lt;div style="margin-bottom:3rem;margin-top:3rem;"&gt;&lt;img style="box-shadow:3px 3px 5px rgba(0, 0, 0, 0.1);" alt=" " src="/resized-image/__size/960x720/__key/communityserver-wikis-components-files/00-00-00-00-46/expressionImage4.png" /&gt;&lt;/div&gt;
&lt;p&gt;&lt;b&gt;Figure &lt;/b&gt;&lt;b&gt;&lt;i&gt;M&amp;nbsp;&lt;/i&gt;&lt;/b&gt;&lt;b&gt;: Sample Test Cases&lt;/b&gt;&lt;/p&gt;
&lt;p&gt;These are test cases a user could have set up for the rule provided in &lt;b&gt;&lt;i&gt;Figure N&lt;/i&gt;&lt;/b&gt;. The first box contains &lt;b&gt;Coverage Tests&lt;/b&gt;. They provide code coverage by testing with expected inputs and outputs. The second box contains &lt;b&gt;Error Handling Tests&lt;/b&gt;. These tests are staged with inputs that would typically result in a denominator of 0. Finally, the third box contains &lt;b&gt;Null Handling Tests&lt;/b&gt;. This is another specific type of error handling tests. They are used to verify that our rule can properly handle null inputs. Note that more than one was required for this rule.&lt;/p&gt;
&lt;h2 id="regression_testing_with_test_cases"&gt;Regression Testing with Test Cases&lt;/h2&gt;
&lt;p&gt;Test cases make it easier and faster to regression test. Before making a change to an existing expression rule, run all existing test cases within the rule and resolve any that have failed. After making the change, add coverage and error handling test cases to test the change. Finally, run all test cases to ensure the update didn&amp;rsquo;t break any existing cases.&lt;/p&gt;
&lt;p&gt;Before a deployment, run the Automated Rules Testing Application (ART) in the target environment (non-production) to ensure all test cases work as expected before the deployment. If any rules do not work, resolve the issues in the lower environment prior to the deployment. After the deployment, re-run ART in the target environment to ensure all new and old test cases work as expected.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;*Note: These examples are not all-encompassing. Best judgement should be used to determine what cases are required.&lt;/p&gt;
&lt;/div&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;
</description></item><item><title>How to Create Expression Rule Test Cases</title><link>https://community.appian.com/success/w/guide/3342/how-to-create-expression-rule-test-cases/revision/5</link><pubDate>Tue, 31 Oct 2023 14:59:36 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:035ef30d-5bb9-47d1-85a5-ea78a8f96c19</guid><dc:creator>joel.larin</dc:creator><comments>https://community.appian.com/success/w/guide/3342/how-to-create-expression-rule-test-cases#comments</comments><description>Revision 5 posted to Guide by joel.larin on 10/31/2023 2:59:36 PM&lt;br /&gt;
&lt;div style="margin:8px 16% 8px 8%;"&gt;
&lt;h2 id="introduction"&gt;Introduction&lt;/h2&gt;
&lt;p&gt;&lt;a href="https://docs.appian.com/suite/help/latest/Expression_Rules.html#test-cases"&gt;Expression rule test cases&lt;/a&gt; enable unit testing with minimal overhead by reducing the time required to test while increasing code quality. Because expression rules have a wide variety of uses, creating meaningful test cases will speed up unit, regression, and exploratory testing. Use the following guidelines to create test cases for your expression rules that will result in greater code coverage for your application. The first section provides guidelines for creating useful test cases, and the following sections explain types of expression rule test cases in greater detail with Appian examples.&lt;/p&gt;
&lt;h2 id="test_case_creation_guidelines"&gt;Test Case Creation Guidelines&lt;/h2&gt;
&lt;p&gt;The following guidelines apply to expression rules which output a value:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Create test cases from the start of application development to aid regression testing.&amp;nbsp;&lt;/li&gt;
&lt;li&gt;If an expression rule calls another expression rule, do not duplicate test cases already created in the child within the parent rule. The parent rule should contain test cases that test any logic within the parent rule itself and should assume the child has sufficient test cases.&lt;/li&gt;
&lt;li&gt;When possible, break down large expressions to individual rules so that it is easier to ensure test coverage with expression rule test cases&lt;/li&gt;
&lt;li&gt;When expression rule test cases are evaluated, the expression is evaluated first, followed by the assertion within the test case. Avoid the use of now() in test case assertions, as this can trigger false negatives due to the dateTime type evaluating the values down to the millisecond. Instead, check whether the field is not blank.&lt;/li&gt;
&lt;li&gt;Use test!output to assert the output equals what you would expect.&lt;/li&gt;
&lt;li&gt;Use &lt;a href="/w/guide/3339/exploratory-testing"&gt;Exploratory Testing&lt;/a&gt; to identify edge cases for which to create test cases.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id="types_of_test_cases"&gt;Types of Test Cases&lt;/h2&gt;
&lt;p&gt;When creating test cases, consider the two types of test cases: &lt;b&gt;coverage tests&lt;/b&gt; and &lt;b&gt;error handling&lt;/b&gt; tests. Every expression rule should always have at least one of each kind of test case.&lt;/p&gt;
&lt;table&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;p&gt;&lt;b&gt;Test Type&lt;/b&gt;&lt;/p&gt;
&lt;/td&gt;
&lt;td&gt;
&lt;p&gt;&lt;b&gt;Description&lt;/b&gt;&lt;/p&gt;
&lt;/td&gt;
&lt;td&gt;
&lt;p&gt;&lt;b&gt;Implementation&lt;/b&gt;&lt;/p&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;p&gt;Coverage&lt;/p&gt;
&lt;/td&gt;
&lt;td&gt;
&lt;p&gt;A coverage test ensures the rule inputs result in the intended output. In other words, an area of the rule has been sufficiently &amp;ldquo;covered&amp;rdquo; via a test case.&lt;/p&gt;
&lt;/td&gt;
&lt;td&gt;
&lt;p&gt;Set inputs to expected values.&amp;nbsp;&lt;/p&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;p&gt;Error Handling&lt;/p&gt;
&lt;/td&gt;
&lt;td&gt;
&lt;p&gt;An error handling test ensures the expression rule has proper error handling.&lt;/p&gt;
&lt;/td&gt;
&lt;td&gt;
&lt;p&gt;Set inputs to values that would typically break the rule.&lt;/p&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;h2 id="creating_coverage_tests"&gt;Creating Coverage Tests&lt;/h2&gt;
&lt;h3&gt;Use the diagram below to determine which test cases are required and how to set assertions.&lt;/h3&gt;
&lt;div style="margin-bottom:3rem;margin-top:3rem;"&gt;&lt;img style="box-shadow:3px 3px 5px rgba(0, 0, 0, 0.1);" alt=" " src="/resized-image/__size/640x480/__key/communityserver-wikis-components-files/00-00-00-00-46/expressionRuleFlow.jpg" /&gt;&lt;/div&gt;
&lt;h2 id="coverage_test_case_examples*"&gt;Coverage Test Case Examples*&lt;/h2&gt;
&lt;h3&gt;Limited Number of Outcomes&lt;/h3&gt;
&lt;p&gt;If your expression rule has a limited number of outcomes, use the below examples to guide your test case creation. Use test!output to assert that the output is equal to the value you expect. Each outcome should have a test case and corresponding assertion.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;b&gt;Nested if()s&lt;/b&gt;: Create 1 test case per possible condition&lt;/li&gt;
&lt;li&gt;&lt;b&gt;Choose()&lt;/b&gt;: Create 1 test case per key&lt;/li&gt;
&lt;li&gt;&lt;b&gt;Mathematical Comparisons&lt;/b&gt;: Create 1 test case per possible comparison&amp;nbsp;
&lt;ul&gt;
&lt;li&gt;For example, for a &lt;i&gt;greater than&lt;/i&gt; comparison, you must have 3 cases covering when the input is less than, equal to, or greater than the comparative value&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;Unlimited Number of Outcomes&lt;/h3&gt;
&lt;p&gt;If your expression rule has an unlimited number of outcomes, use the below examples to guide your test case creation. Use test!output where it makes sense to ensure the output is equal to the expected value.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;b&gt;Calculations&lt;/b&gt;: Based on the calculation being run, identify inputs that will cover groupings of possible outcomes. The asserted output should be calculated outside of Appian and then asserted within the case.
&lt;ul&gt;
&lt;li&gt;For example, if you have a rule that is executing the following calculation: &lt;i&gt;A-B&lt;/i&gt;, with integers &lt;i&gt;A&lt;/i&gt; and &lt;i&gt;B&lt;/i&gt;, test cases should cover the following scenarios as they all would reveal something different about the calculation:
&lt;ul&gt;
&lt;li&gt;A&amp;gt;B (output is positive)&lt;/li&gt;
&lt;li&gt;A&amp;lt;B (output is negative)&lt;/li&gt;
&lt;li&gt;A=B (output is 0)&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;ul&gt;
&lt;li&gt;&lt;b&gt;Integrations: Expression Rule Test Cases can be used to test integration connectivity prior to a deployment. Create an expression rule that calls the integration and a test case that passes in data to populate the request. Set the assertion to &amp;ldquo;expression evaluates to true&amp;rdquo;. The expression should check that the &amp;ldquo;success&amp;rdquo; output of the integration = true. Add these expression rules to an app that is deployed prior to your business application.&lt;/b&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Date Times&lt;/strong&gt;:&amp;nbsp;Create test cases which cover all groupings of expected outcomes, including all known edge cases. Assert that the output is correct for each test case.&amp;nbsp;
&lt;ul&gt;
&lt;li&gt;For example, if a rule checks whether a date is a work day (calisworkday(datetime)), create test cases with the following inputs to test the possible outcomes. Use the value in parenthesis to assert that test!output is the correct value:
&lt;ul&gt;
&lt;li&gt;A work day (true)&lt;/li&gt;
&lt;li&gt;A weekend day (false)&lt;/li&gt;
&lt;li&gt;A holiday (false)&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;ul&gt;
&lt;li&gt;Consider test cases that go &amp;ldquo;stale&amp;rdquo; (rules where the output depends on whether inputs are in the past, future, etc). Avoid using hard coded dates and instead, use the appropriate Appian date and time functions (now(), today(), etc.) to ensure that test inputs will last for the lifetime of the application. As mentioned previously, do not use now() in test case assertions.&lt;/li&gt;
&lt;li&gt;If the rule contains calculations on dates in particular timezones, use the gmt() and local() functions to enforce a timezone and assert the correct output for that timezone.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;b&gt;Type Constructors&lt;/b&gt;:&amp;nbsp;Test cases are only necessary to test any logic within the rule that is outside of the constructor itself. &amp;ldquo;Assertion expression evaluates to true&amp;rdquo; is typically useful for these types of test cases.
&lt;ul&gt;
&lt;li&gt;If the rule takes a raw set of data and only casts items that meet specific criteria, a test case can be created in which you validate that all items in the output meet that criteria.&lt;/li&gt;
&lt;li&gt;If the rule casts individual fields from a rule input to a new data type, create a test case that asserts that each field equals what is expected by using test!output.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id="creating_error_handling_tests"&gt;Creating Error Handling Tests&lt;/h2&gt;
&lt;p&gt;Error handling test cases should be created based on the functions and inputs of the rule. &lt;b&gt;All &lt;/b&gt;rules should have null handling test cases (unless already covered by a parent rule), while other error handling scenarios should be determined at the Designer&amp;rsquo;s discretion. All error handling cases should have the test output match an asserted output.&lt;/p&gt;
&lt;h2 id="error_handling_test_case_examples*"&gt;Error Handling Test Case Examples*&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;&lt;b&gt;Null Handling: Set one, some, or all rule inputs to null to ensure the rule executes properly and outputs an expected value. In many cases, more than one null handling test case may be necessary.&lt;/b&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;div style="margin-bottom:3rem;margin-top:3rem;"&gt;&lt;img style="box-shadow:3px 3px 5px rgba(0, 0, 0, 0.1);" alt=" " src="/resized-image/__size/960x720/__key/communityserver-wikis-components-files/00-00-00-00-46/expressionImage1.png" /&gt;&lt;/div&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Invalid Mathematical Expressions&lt;/strong&gt;: In rules that execute a calculation, provide inputs that produce an invalid calculation, such as a denominator of zero. Ensure the rule still executes properly and outputs the expected value.
&lt;ul&gt;
&lt;li&gt;For example, if your rule is calculating the square root of the difference between &lt;i&gt;A &lt;/i&gt;and &lt;i&gt;B&lt;/i&gt;, create a case in which B &amp;gt; A.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;ul&gt;
&lt;li&gt;&lt;b&gt;Functions that error given invalid inputs: If a rule uses functions that produce an expression error if the input is invalid (e.g. user/group functions, not(), etc), create a test case for each invalid input to verify that expression errors are avoided.&lt;/b&gt;
&lt;ul&gt;
&lt;li&gt;For example, if your rule has a username input, cases should be created in which a random non-username string is passed in. The rule should be coded to handle this case properly.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Date Times&lt;/strong&gt;: Create test cases with datetimes outside of what the rule expects to ensure that the rule handles them appropriately.&lt;/li&gt;
&lt;/ul&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Queries&lt;/strong&gt;:&amp;nbsp;
&lt;ul&gt;
&lt;li&gt;For queries in which data is consistent across environments, regardless of user interaction with the system (i.e. reference data), create test cases with data that will always be returned and assert that the test output matches the desired value.&lt;/li&gt;
&lt;li&gt;For queries on transactional data, expression rule test cases should not be used to validate that a particular data set is returned because data can vary based on the environment and user interaction. However, test cases can still be used in the following ways:
&lt;ul&gt;
&lt;li&gt;On all expression rules that have queries, you can create a test case which asserts that the &amp;ldquo;&lt;a href="https://docs.appian.com/suite/help/20.3/Expression_Rules.html#test-case-assertions"&gt;Test completes without errors&lt;/a&gt;&amp;rdquo; to validate &lt;b&gt;database connectivity&lt;/b&gt;.&amp;nbsp;&lt;/li&gt;
&lt;li&gt;If the query ignores null filter values, include a test case which passes in values for all possible filters and asserts that the test completes without errors to ensure that all&lt;b&gt; field names and filter configurations&lt;/b&gt; are valid.&lt;/li&gt;
&lt;li&gt;If the query does not ignore null filter values, create &lt;b&gt;null-handling&lt;/b&gt; test cases for the rule.&amp;nbsp;&lt;/li&gt;
&lt;li&gt;For all filters that are created, test cases can be used to validate that the returned results match the&lt;b&gt; filter value&lt;/b&gt; that was passed in. For example, if &amp;ldquo;true&amp;rdquo; is passed into an &amp;ldquo;isActive&amp;rdquo; filter in the query, a test case can validate that all results returned have isActive=true. For test cases like these, include appropriate null handling for when no data matches the filter criteria.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Use test cases to assert that the output is of the same &lt;b&gt;data type&lt;/b&gt; as the data entity being queried. This can be done using the &amp;ldquo;&lt;a href="https://docs.appian.com/suite/help/20.3/Expression_Rules.html#test-case-assertions"&gt;Assertion expression evaluates to true&lt;/a&gt;&amp;rdquo; assertion option, where the expression would check that the type of test!output matches the expected type using the typeof() function.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;i&gt;Note: Expression rules containing queries should only include the a!queryEntity() function. Any expressions to manipulate the data or output different values based on the query results should be done in separate expression rules, using the results of the query as a rule input. This allows flexibility to assert that the manipulation or conditional output operates correctly without relying on transaction data that can change across Appian environments.&lt;/i&gt;&lt;/p&gt;
&lt;h2 id="example_expression_rule"&gt;Example Expression Rule&lt;/h2&gt;
&lt;h4&gt;An example expression rule that has coverage tests and error handling tests can be found below.&lt;/h4&gt;
&lt;div style="margin-bottom:3rem;margin-top:3rem;"&gt;&lt;img style="box-shadow:3px 3px 5px rgba(0, 0, 0, 0.1);" alt=" " src="/resized-image/__size/960x720/__key/communityserver-wikis-components-files/00-00-00-00-46/expressionImage2.png" /&gt;&lt;/div&gt;
&lt;div style="margin-bottom:3rem;margin-top:3rem;"&gt;&lt;img style="box-shadow:3px 3px 5px rgba(0, 0, 0, 0.1);" alt=" " src="/resized-image/__size/960x720/__key/communityserver-wikis-components-files/00-00-00-00-46/expressionImage3.png" /&gt;&lt;/div&gt;
&lt;p&gt;&lt;b&gt;Figure &lt;/b&gt;&lt;b&gt;&lt;i&gt;N&amp;nbsp;&lt;/i&gt;&lt;/b&gt;&lt;b&gt;: Sample Expression Rule&lt;/b&gt;&lt;/p&gt;
&lt;div style="margin-bottom:3rem;margin-top:3rem;"&gt;&lt;img style="box-shadow:3px 3px 5px rgba(0, 0, 0, 0.1);" alt=" " src="/resized-image/__size/960x720/__key/communityserver-wikis-components-files/00-00-00-00-46/expressionImage4.png" /&gt;&lt;/div&gt;
&lt;p&gt;&lt;b&gt;Figure &lt;/b&gt;&lt;b&gt;&lt;i&gt;M&amp;nbsp;&lt;/i&gt;&lt;/b&gt;&lt;b&gt;: Sample Test Cases&lt;/b&gt;&lt;/p&gt;
&lt;p&gt;These are test cases a user could have set up for the rule provided in &lt;b&gt;&lt;i&gt;Figure N&lt;/i&gt;&lt;/b&gt;. The first box contains &lt;b&gt;Coverage Tests&lt;/b&gt;. They provide code coverage by testing with expected inputs and outputs. The second box contains &lt;b&gt;Error Handling Tests&lt;/b&gt;. These tests are staged with inputs that would typically result in a denominator of 0. Finally, the third box contains &lt;b&gt;Null Handling Tests&lt;/b&gt;. This is another specific type of error handling tests. They are used to verify that our rule can properly handle null inputs. Note that more than one was required for this rule.&lt;/p&gt;
&lt;h2 id="regression_testing_with_test_cases"&gt;Regression Testing with Test Cases&lt;/h2&gt;
&lt;p&gt;Test cases make it easier and faster to regression test. Before making a change to an existing expression rule, run all existing test cases within the rule and resolve any that have failed. After making the change, add coverage and error handling test cases to test the change. Finally, run all test cases to ensure the update didn&amp;rsquo;t break any existing cases.&lt;/p&gt;
&lt;p&gt;Before a deployment, run the Automated Rules Testing Application (ART) in the target environment (non-production) to ensure all test cases work as expected before the deployment. If any rules do not work, resolve the issues in the lower environment prior to the deployment. After the deployment, re-run ART in the target environment to ensure all new and old test cases work as expected.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;*Note: These examples are not all-encompassing. Best judgement should be used to determine what cases are required.&lt;/p&gt;
&lt;/div&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;
</description></item><item><title>How to Create Expression Rule Test Cases</title><link>https://community.appian.com/success/w/guide/3342/how-to-create-expression-rule-test-cases/revision/4</link><pubDate>Tue, 31 Oct 2023 13:25:50 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:035ef30d-5bb9-47d1-85a5-ea78a8f96c19</guid><dc:creator>matt.cosenza</dc:creator><comments>https://community.appian.com/success/w/guide/3342/how-to-create-expression-rule-test-cases#comments</comments><description>Revision 4 posted to Guide by matt.cosenza on 10/31/2023 1:25:50 PM&lt;br /&gt;
&lt;div style="margin:8px 16% 8px 8%;"&gt;
&lt;p&gt;&lt;/p&gt;
sdfs&lt;/div&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;
</description></item><item><title>How to Create Expression Rule Test Cases</title><link>https://community.appian.com/success/w/guide/3342/how-to-create-expression-rule-test-cases/revision/3</link><pubDate>Tue, 31 Oct 2023 13:22:49 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:035ef30d-5bb9-47d1-85a5-ea78a8f96c19</guid><dc:creator>matt.cosenza</dc:creator><comments>https://community.appian.com/success/w/guide/3342/how-to-create-expression-rule-test-cases#comments</comments><description>Revision 3 posted to Guide by matt.cosenza on 10/31/2023 1:22:49 PM&lt;br /&gt;
&lt;div style="margin:8px 16% 8px 8%;"&gt;
&lt;p&gt;Automated testing reduces the amount of manual testing necessary in an Appian application and reduces risk at each stage of the application development lifecycle. Automated testing can be used throughout the Appian application development lifecycle to:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Test new rules created within an Appian application such as conditional fields, complex business logic, or validations&lt;/li&gt;
&lt;li&gt;Complete functional testing to ensure all requirements are verified and validated&lt;/li&gt;
&lt;li&gt;Regression test the application to ensure that existing functionality is not affected when:
&lt;ul&gt;
&lt;li&gt;Appian application gets promoted to different environments&lt;/li&gt;
&lt;li&gt;New functionality is created&lt;/li&gt;
&lt;li&gt;&lt;a href="/w/article/3280/managing-multiple-concurrent-delivery-teams"&gt;Concurrent development teams&lt;/a&gt; are established&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Fast forward to a particular step in a workflow to perform manual testing from there&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Automated testing should be implemented early in a project to prevent buildup of functionality for which test scripts must be written. The longer a team waits to set up automated testing, the more burdensome it can become to do so. Conversely, if test scripts are written for functionality that is highly likely to change, it can be&amp;nbsp;time-consuming to update them to keep up with changing requirements. So, a project team must work together to achieve a balance between these alternatives by determining when and for what purposes to design automated testing scripts.&lt;/p&gt;
&lt;p&gt;It is not recommended to have 100% test coverage of an application through Automated Testing due to the below reasons:&amp;nbsp;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;It is time consuming to plan/implement test scripts and run the tests to cover the entire application.&amp;nbsp;&lt;/li&gt;
&lt;li&gt;We currently do not have a method to gauge completeness of test coverage for an application.&lt;/li&gt;
&lt;li&gt;Some areas of the application may change frequently over time and integrations may depend on external systems.&amp;nbsp;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;These factors can make it difficult to get a good return on the time investment put into building test scripts to cover all functionality in an application.Given that 100% of the application cannot reliably be validated through automated testing, the core team (developers, PO, QAs) must collaborate in order to identify highest priority items to be addressed. Teams should consider factors such as level of effort to create new automated tests and level of risk in determining where to focus test coverage. Based on this collaboration, the automated testing suite can be incrementally updated to ensure highest value areas are targeted first.&lt;/p&gt;
&lt;p&gt;Automated testing is not the same as performance testing. To find more information on performance testing best practices and tools such as JMeter and Loadrunner, see &lt;a style="background-color:#ffff99;" href="/w/article/3216/performance-and-load-testing"&gt;Performance and Load Testing&lt;/a&gt;.&lt;/p&gt;
&lt;h2 id="automated_testing_tools_for_appian_applications"&gt;Automated Testing Tools for Appian Applications&lt;/h2&gt;
&lt;p&gt;The following tools can be used to automate testing for Appian applications. The Tools In Appian section describes automated testing features that come OOTB with Appian, which should be used wherever possible. The External Tools section includes the available tools which were not built for Appian, and the Tools Built for Appian section describes tools built for Appian from external tools to facilitate automated testing in Appian.&lt;/p&gt;
&lt;table style="border-color:#000000;" height="114"&gt;
&lt;tbody&gt;
&lt;tr&gt;&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;p&gt;&lt;strong&gt;Expression Rule Test Cases:&amp;nbsp;&lt;/strong&gt;Test cases can be configured for expression rules to test outputs with any combination of inputs. These function as automated tests built into the expression rule object. See the &lt;a href="https://docs.appian.com/suite/help/latest/Automated_Testing_for_Expression_Rules.html"&gt;documentation&lt;/a&gt; for more information and instructions on when and how to use expression rule test cases. By importing the &lt;a href="/b/appmarket/posts/automated-rule-testing-application"&gt;Automated Rule Testing&lt;/a&gt;&amp;nbsp;application&amp;nbsp;to an environment, administrators can run all test cases regularly and leverage reporting on failures and successes. This will help identify bugs in expression rules faster, speed up regression testing after rules have changed, and make smoke testing deployments even faster.&lt;/p&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;p&gt;These should generally only be used when necessary. Otherwise, it is recommended to use &lt;a href="/w/guide/3313/automated-testing-with-fitnesse-for-appian"&gt;FitNesse For Appian&lt;/a&gt; or &lt;a href="/b/appmarket/posts/appian_2d00_selenium_2d00_api"&gt;Appian&amp;rsquo;s Selenium API&lt;/a&gt; with Cucumber (described in the Tools Built for Appian section below) because these are preconfigured to work for Appian applications.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Selenium:&amp;nbsp;&lt;/strong&gt;Selenium is an automated testing tool that is able to control a web browser. Selenium has two different products: WebDriver and IDE. The WebDriver is a collection of language specific bindings that drive a web browser while the IDE is an add-on to Firefox that is able to record and playback interactions with the web browser.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;For more information, see the &lt;a href="http://www.seleniumhq.org/"&gt;Selenium Website&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;strong&gt;FitNesse:&amp;nbsp;&lt;/strong&gt;FitNesse is automated testing software which uses a wiki language and allows for a low barrier to entry and ease of use. FitNesse test scripts and test suites are created in the wiki language that map out to functions written in a development language that wrap a Selenium Webdriver to perform actions on an Appian application.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;For more information, see the &lt;a href="http://www.fitnesse.org/"&gt;FitNesse Website&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;strong&gt;Cucumber:&amp;nbsp;&lt;/strong&gt;Cucumber is an automated test tool utilizing Behavior Driven Development (BDD) that allows testers to specify test scenarios in a human readable form. Cucumber can be used to create test scripts in plain language with Gherkin syntax. One benefit of Cucumber is that the Product Owner or business users are able to write test cases without a technical background. These test scripts map to functions in a development language (such as Java or Ruby) that wrap a Selenium Webdriver to perform the specified actions on an Appian application.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;For more information, see the &lt;a href="https://cucumber.io/"&gt;Cucumber Website&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;p&gt;Appian has created the following tools to reduce the amount of work required to automate testing of Appian applications.&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Appian Selenium API: &lt;/b&gt;The Appian Selenium API allows you to run Appian UI tests directly from a JUnit Test Case, create your own Gherkin steps and step definitions with Cucumber, and run tests from any java based test tool of your choice without having to create the necessary xpath for selenium to interact with Appian. When using Cucumber, it is recommended to use this API to customize step definitions to match the business users&amp;rsquo; phrasing.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href="/b/appmarket/posts/appian_2d00_selenium_2d00_api"&gt;Download the Appian Selenium API&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;strong&gt;FitNesse for Appian:&lt;/strong&gt; Appian has written WebDriver fixtures to leverage Selenium and FitNesse to create FitNesse for Appian. This tool is easier to set up than Fitnesse and provides a faster way to build automated tests for Appian applications. This is complemented by the &lt;a href="/b/appmarket/posts/fit-fam-fitnesse-for-appian-generator"&gt;FitFam application&lt;/a&gt;, which allows users to create FitNesse test scripts for complex interfaces solely by interacting with the interface.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href="/b/appmarket/posts/fitnesse-for-appian"&gt;Download FitNesse for Appian&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;For more information, see the &lt;a href="/w/guide/3310/automated-testing-with-fitnesse-for-appian"&gt;FitNesse for Appian Documentation&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;For implementation guidance, see the &lt;a href="/w/guide/3212/fitnesse-for-appian-best-practices#designing_appian_applications_for_fitnesse"&gt;FitNesse for Appian Best Practices&lt;/a&gt; Play&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;b&gt;Cucumber for Appian:&lt;/b&gt; Cucumber for Appian is a client-side tool that provides a sample set of step definitions similar to those provided by &lt;a href="/w/guide/3313/automated-testing-with-fitnesse-for-appian"&gt;FitNesse for Appian&lt;/a&gt;. Note that these step definitions are not application specific. Features and scenarios written with these sample step definitions will not embrace the &lt;a href="https://cucumber.io/docs/bdd/"&gt;Behavior Driven Development (BDD)&lt;/a&gt; aspects of Cucumber. Cucumber for Appian is a good starting point for teams not familiar with Cucumber to get familiar with Cucumber before writing their own cucumber step definitions in Java. Additionally, the sample step definitions will allow testers to write a fairly complete set of tests without needing to know Java.&lt;/p&gt;
&lt;p&gt;Teams experienced in writing automated tests as code might find the sample step definitions provided by Cucumber for Appian limiting. For example, gherkin syntax does not allow for saving variables between steps or looping. We recommend leveraging the &lt;a href="/b/appmarket/posts/appian_2d00_selenium_2d00_api"&gt;Appian Selenium API&lt;/a&gt; to write your own step definitions for testers that want to trade the simplicity of Cucumber for Appian with the power provided by code. Custom Step Definitions in tandem with the Appian Selenium API will allow you to write future proof tests that will work between upgrades and embrace BDD.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Download &lt;a href="/b/appmarket/posts/cucumber-for-appian"&gt;Cucumber for Appian&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;For more information, see the &lt;a href="/w/guide/3311/automated-testing-with-cucumber-for-appian"&gt;Cucumber for Appian&lt;/a&gt; Playbook Play&lt;/p&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;h3&gt;&lt;/h3&gt;
&lt;h3&gt;&lt;/h3&gt;
&lt;/div&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;
</description></item><item><title>How to Create Expression Rule Test Cases</title><link>https://community.appian.com/success/w/guide/3342/how-to-create-expression-rule-test-cases/revision/2</link><pubDate>Tue, 31 Oct 2023 13:18:22 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:035ef30d-5bb9-47d1-85a5-ea78a8f96c19</guid><dc:creator>matt.cosenza</dc:creator><comments>https://community.appian.com/success/w/guide/3342/how-to-create-expression-rule-test-cases#comments</comments><description>Revision 2 posted to Guide by matt.cosenza on 10/31/2023 1:18:22 PM&lt;br /&gt;
&lt;div style="margin:8px 16% 8px 8%;"&gt;
&lt;p&gt;Automated testing reduces the amount of manual testing necessary in an Appian application and reduces risk at each stage of the application development lifecycle. Automated testing can be used throughout the Appian application development lifecycle to:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Test new rules created within an Appian application such as conditional fields, complex business logic, or validations&lt;/li&gt;
&lt;li&gt;Complete functional testing to ensure all requirements are verified and validated&lt;/li&gt;
&lt;li&gt;Regression test the application to ensure that existing functionality is not affected when:
&lt;ul&gt;
&lt;li&gt;Appian application gets promoted to different environments&lt;/li&gt;
&lt;li&gt;New functionality is created&lt;/li&gt;
&lt;li&gt;&lt;a href="/w/article/3280/managing-multiple-concurrent-delivery-teams"&gt;Concurrent development teams&lt;/a&gt; are established&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Fast forward to a particular step in a workflow to perform manual testing from there&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Automated testing should be implemented early in a project to prevent buildup of functionality for which test scripts must be written. The longer a team waits to set up automated testing, the more burdensome it can become to do so. Conversely, if test scripts are written for functionality that is highly likely to change, it can be&amp;nbsp;time-consuming to update them to keep up with changing requirements. So, a project team must work together to achieve a balance between these alternatives by determining when and for what purposes to design automated testing scripts.&lt;/p&gt;
&lt;p&gt;It is not recommended to have 100% test coverage of an application through Automated Testing due to the below reasons:&amp;nbsp;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;It is time consuming to plan/implement test scripts and run the tests to cover the entire application.&amp;nbsp;&lt;/li&gt;
&lt;li&gt;We currently do not have a method to gauge completeness of test coverage for an application.&lt;/li&gt;
&lt;li&gt;Some areas of the application may change frequently over time and integrations may depend on external systems.&amp;nbsp;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;These factors can make it difficult to get a good return on the time investment put into building test scripts to cover all functionality in an application.Given that 100% of the application cannot reliably be validated through automated testing, the core team (developers, PO, QAs) must collaborate in order to identify highest priority items to be addressed. Teams should consider factors such as level of effort to create new automated tests and level of risk in determining where to focus test coverage. Based on this collaboration, the automated testing suite can be incrementally updated to ensure highest value areas are targeted first.&lt;/p&gt;
&lt;p&gt;Automated testing is not the same as performance testing. To find more information on performance testing best practices and tools such as JMeter and Loadrunner, see &lt;a style="background-color:#ffff99;" href="/w/article/3216/performance-and-load-testing"&gt;Performance and Load Testing&lt;/a&gt;.&lt;/p&gt;
&lt;h2 id="automated_testing_tools_for_appian_applications"&gt;Automated Testing Tools for Appian Applications&lt;/h2&gt;
&lt;p&gt;The following tools can be used to automate testing for Appian applications. The Tools In Appian section describes automated testing features that come OOTB with Appian, which should be used wherever possible. The External Tools section includes the available tools which were not built for Appian, and the Tools Built for Appian section describes tools built for Appian from external tools to facilitate automated testing in Appian.&lt;/p&gt;
&lt;table style="border-color:#000000;" height="114"&gt;
&lt;tbody&gt;
&lt;tr&gt;&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;p&gt;&lt;strong&gt;Expression Rule Test Cases:&amp;nbsp;&lt;/strong&gt;Test cases can be configured for expression rules to test outputs with any combination of inputs. These function as automated tests built into the expression rule object. See the &lt;a href="https://docs.appian.com/suite/help/19.1/Automated_Testing_for_Expression_Rules.html"&gt;documentation&lt;/a&gt; for more information and instructions on when and how to use expression rule test cases. By importing the &lt;a href="/b/appmarket/posts/automated-rule-testing-application"&gt;Automated Rule Testing&lt;/a&gt;&amp;nbsp;application&amp;nbsp;to an environment, administrators can run all test cases regularly and leverage reporting on failures and successes. This will help identify bugs in expression rules faster, speed up regression testing after rules have changed, and make smoke testing deployments even faster.&lt;/p&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;p&gt;These should generally only be used when necessary. Otherwise, it is recommended to use &lt;a href="/w/guide/3313/automated-testing-with-fitnesse-for-appian"&gt;FitNesse For Appian&lt;/a&gt; or &lt;a href="/b/appmarket/posts/appian_2d00_selenium_2d00_api"&gt;Appian&amp;rsquo;s Selenium API&lt;/a&gt; with Cucumber (described in the Tools Built for Appian section below) because these are preconfigured to work for Appian applications.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Selenium:&amp;nbsp;&lt;/strong&gt;Selenium is an automated testing tool that is able to control a web browser. Selenium has two different products: WebDriver and IDE. The WebDriver is a collection of language specific bindings that drive a web browser while the IDE is an add-on to Firefox that is able to record and playback interactions with the web browser.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;For more information, see the &lt;a href="http://www.seleniumhq.org/"&gt;Selenium Website&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;strong&gt;FitNesse:&amp;nbsp;&lt;/strong&gt;FitNesse is automated testing software which uses a wiki language and allows for a low barrier to entry and ease of use. FitNesse test scripts and test suites are created in the wiki language that map out to functions written in a development language that wrap a Selenium Webdriver to perform actions on an Appian application.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;For more information, see the &lt;a href="http://www.fitnesse.org/"&gt;FitNesse Website&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;strong&gt;Cucumber:&amp;nbsp;&lt;/strong&gt;Cucumber is an automated test tool utilizing Behavior Driven Development (BDD) that allows testers to specify test scenarios in a human readable form. Cucumber can be used to create test scripts in plain language with Gherkin syntax. One benefit of Cucumber is that the Product Owner or business users are able to write test cases without a technical background. These test scripts map to functions in a development language (such as Java or Ruby) that wrap a Selenium Webdriver to perform the specified actions on an Appian application.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;For more information, see the &lt;a href="https://cucumber.io/"&gt;Cucumber Website&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;p&gt;Appian has created the following tools to reduce the amount of work required to automate testing of Appian applications.&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Appian Selenium API: &lt;/b&gt;The Appian Selenium API allows you to run Appian UI tests directly from a JUnit Test Case, create your own Gherkin steps and step definitions with Cucumber, and run tests from any java based test tool of your choice without having to create the necessary xpath for selenium to interact with Appian. When using Cucumber, it is recommended to use this API to customize step definitions to match the business users&amp;rsquo; phrasing.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href="/b/appmarket/posts/appian_2d00_selenium_2d00_api"&gt;Download the Appian Selenium API&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;strong&gt;FitNesse for Appian:&lt;/strong&gt; Appian has written WebDriver fixtures to leverage Selenium and FitNesse to create FitNesse for Appian. This tool is easier to set up than Fitnesse and provides a faster way to build automated tests for Appian applications. This is complemented by the &lt;a href="/b/appmarket/posts/fit-fam-fitnesse-for-appian-generator"&gt;FitFam application&lt;/a&gt;, which allows users to create FitNesse test scripts for complex interfaces solely by interacting with the interface.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href="/b/appmarket/posts/fitnesse-for-appian"&gt;Download FitNesse for Appian&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;For more information, see the &lt;a href="/w/guide/3310/automated-testing-with-fitnesse-for-appian"&gt;FitNesse for Appian Documentation&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;For implementation guidance, see the &lt;a href="/w/guide/3212/fitnesse-for-appian-best-practices#designing_appian_applications_for_fitnesse"&gt;FitNesse for Appian Best Practices&lt;/a&gt; Play&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;b&gt;Cucumber for Appian:&lt;/b&gt; Cucumber for Appian is a client-side tool that provides a sample set of step definitions similar to those provided by &lt;a href="/w/guide/3313/automated-testing-with-fitnesse-for-appian"&gt;FitNesse for Appian&lt;/a&gt;. Note that these step definitions are not application specific. Features and scenarios written with these sample step definitions will not embrace the &lt;a href="https://cucumber.io/docs/bdd/"&gt;Behavior Driven Development (BDD)&lt;/a&gt; aspects of Cucumber. Cucumber for Appian is a good starting point for teams not familiar with Cucumber to get familiar with Cucumber before writing their own cucumber step definitions in Java. Additionally, the sample step definitions will allow testers to write a fairly complete set of tests without needing to know Java.&lt;/p&gt;
&lt;p&gt;Teams experienced in writing automated tests as code might find the sample step definitions provided by Cucumber for Appian limiting. For example, gherkin syntax does not allow for saving variables between steps or looping. We recommend leveraging the &lt;a href="/b/appmarket/posts/appian_2d00_selenium_2d00_api"&gt;Appian Selenium API&lt;/a&gt; to write your own step definitions for testers that want to trade the simplicity of Cucumber for Appian with the power provided by code. Custom Step Definitions in tandem with the Appian Selenium API will allow you to write future proof tests that will work between upgrades and embrace BDD.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Download &lt;a href="/b/appmarket/posts/cucumber-for-appian"&gt;Cucumber for Appian&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;For more information, see the &lt;a href="/w/guide/3311/automated-testing-with-cucumber-for-appian"&gt;Cucumber for Appian&lt;/a&gt; Playbook Play&lt;/p&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;h3&gt;&lt;/h3&gt;
&lt;h3&gt;&lt;/h3&gt;
&lt;/div&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;
</description></item><item><title>How to Create Expression Rule Test Cases</title><link>https://community.appian.com/success/w/guide/3342/how-to-create-expression-rule-test-cases/revision/1</link><pubDate>Wed, 13 Sep 2023 14:07:57 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:035ef30d-5bb9-47d1-85a5-ea78a8f96c19</guid><dc:creator>joel.larin</dc:creator><comments>https://community.appian.com/success/w/guide/3342/how-to-create-expression-rule-test-cases#comments</comments><description>Revision 1 posted to Guide by joel.larin on 9/13/2023 2:07:57 PM&lt;br /&gt;
&lt;p&gt;dfs&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;
</description></item></channel></rss>