Skip to main content

Step 3: Creating tests

πŸ§ͺ Step 3: End-to-End Testing for Bank Holidays Service

The Variant platform provides a flexible way to test entire API flows using the built-in test runner. Here, we demonstrate three full integration tests covering:

  • Valid region responses

  • Date-specific logic

  • Error handling for invalid inputs

These tests are defined declaratively using Y# in your !Main.yaml file and executed via the /api/integrationtests endpoint.


βœ… Test 1: Valid Region Requests​

This test ensures that calling GET /api/bankholidays/{region}:

  • Returns the correct region

  • Includes the expected number of holiday events

- pipe: Variant.TestRunner.Default.RunTests
TEST_NAME_PREFIX: GET_api_bankholidays_
TEST_DATA: |-
| TestName | Region | Count |
| england | england-and-wales | 75 |
| scotland | scotland | 84 |
| ni | northern-ireland | 93 |
DEFAULTS_ADDITIONAL_ROW_INFO:
HostUrl: ${Request.Header.Scheme}://${Request.Header.Host}
ACT_PIPES:
- pipe: _CallService
HTTP_URL: ${Defaults.Additional.HostUrl}/api/bankholidays/${Defaults.Region}
HTTP_METHOD: GET
HTTP_READ_AS: JToken
ASSERTION_PIPES:
- pipe: Variant.TestRunner.Default.Assert
ASSERT_EXPRESSION: >-
"${Response.region}" == "${Defaults.Region}" &&
${Response.events.Count()} == ${Defaults.Count}

βœ… Test 2: Bank Holiday Date Check​

This test targets the GET /api/bankholidays/{region}/{date} endpoint to:

  • Check whether a specific date is or is not a bank holiday

  • Validate correct content type returned

- pipe: Variant.TestRunner.Default.RunTests
TEST_NAME_PREFIX: GET_api_bankholidays_date_
TEST_DATA: |-
| TestName | Region | Date | Result |
| IsBankHoliday | england-and-wales | 2019-01-01 | True |
| IsNotBankHoliday | england-and-wales | 2019-01-03 | False |
DEFAULTS_ADDITIONAL_ROW_INFO:
HostUrl: ${Request.Header.Scheme}://${Request.Header.Host}
ACT_PIPES:
- pipe: _CallService
HTTP_URL: ${Defaults.Additional.HostUrl}/api/bankholidays/${Defaults.Region}/${Defaults.Date}
HTTP_METHOD: GET
HTTP_READ_AS: JToken
ASSERTION_PIPES:
- pipe: Variant.TestRunner.Default.Assert
ASSERT_EXPRESSION: >-
"${Response.isBankHoliday.ToString()}" == "${Defaults.Result}" &&
"${ResponseContentHeaders.Content-Type}" == "application/json"

βœ… Test 3: Input Validation & Error Handling​

This test covers failure scenarios such as:

  • Invalid region names (e.g. xyz)

  • Improperly formatted dates (e.g. 201901-03)

Using RunExceptionTests, we validate that the service:

  • Returns the appropriate HTTP status code

  • Returns the correct error message

- pipe: Variant.TestRunner.Default.RunExceptionTests
EXCEPTION_TEST_NS: TestException
TEST_NAME_PREFIX: Exceptions_
TEST_DATA: |-
| TestName | Region | Date | ErrorText | StatusCode |
| InvalidRegion | xyz | 2019-01-01 | Invalid region: xyz | 400 |
| InvalidDate | england-and-wales | 201901-03 | Invalid date format | 400 |
DEFAULTS_ADDITIONAL_ROW_INFO:
HostUrl: ${Request.Header.Scheme}://${Request.Header.Host}
ACT_PIPES:
- pipe: _CallService
HTTP_URL: ${Defaults.Additional.HostUrl}/api/bankholidays/${Defaults.Region}/${Defaults.Date}
HTTP_METHOD: GET
HTTP_READ_AS: String
ASSERTION_PIPES:
- pipe: Variant.TestRunner.Default.Assert
ASSERT_EXPRESSION: >-
"${TestException.ErrorText}" == "${Defaults.ErrorText}" &&
${TestException.OutcomeId} == ${Defaults.StatusCode}

These tests provide full confidence in both the functional correctness and robustness of your service.

βœ… Summary​

With Variant’s built-in test runner, you can:

  • Define tests using declarative Y#

  • Run them via a dedicated /api/integrationtests endpoint

  • Test single logic units or full API pipelines

  • Store test results in Azure Tables (automatically handled)

This structured testing approach promotes TDD and keeps services robust and production-ready.