Unit Tests
Use Xano's one-click test generation to ensure your application always behaves as expected
Last updated
Use Xano's one-click test generation to ensure your application always behaves as expected
Last updated
The fastest way to create a unit test is by using Run & Debug. Once you are achieving the desired result by running your function stack, you can click Create Unit Test under the result.
You can also create a test manually at any time from the API settings menu.
Give your unit test a name, a description, and the data source that it should use to run the test if different from your live data source.
Unit tests are defined by your input and expects.
Inputs align with the inputs that your function stack expects. You can fill out any desired values here that you would like to use to run the test. If you used the Create Unit Test option in Run & Debug, this should already be populated for you.
Expects are the statements that are used to validate your test. These could be anything from a simple equals statement, or use more complex operators based on your needs.
Your unit test can have multiple expect statements, which can be added by clicking the + Add an expect statement option.
When creating a unit test on a function stack that requires authentication, you can provide an auth token and extras just like you would during Run & Debug.
To avoid having to recycle the auth token upon expiration, we have added the ability to ignore auth token expiration when running your unit tests.
Once you have your unit tests built, you can always run them individually from that API's testing panel. If you want to run all of your tests at once, you can use the testing suite.
In the left-hand navigation menu, find your Library and click Unit Tests.
Once inside the testing suite, you can perform the following actions:
Review where your application has and is missing coverage.
Run all tests at once.
For complex applications with a significant number of objects, you have the ability to dial down further into checking coverage and tests for functions, APIs, and middleware separately. You can also filter your tests by tested / untested only, or failed only, to quickly understand where your attention should be to ensure 100% coverage and success.
Use the button to delete expect statements.
Use the button to check all expect statements, or you can run them selectively with the button.