The Automated Functional Tests is a sample project demonstrating functional testing created using BDDfy and XUnit.
The project contains the framework for testing API's and a number of test cases to demonstrate usage of the framework.
- xUnit (Test adapter)
- BDDfy (BDD tool)
- HttpClient (For API requests)
- Shouldly (Assertions)
API.FunctionalTests folder and run the following command:
Test Folder structure
This folder contains builder classes that are used to create POCO's (Plain Old CLR Object) for objects used in API requests. Ideally there should be a model for every request and response that is used within the tests. The aim of these classes is to make it as easy as possible for developers to generate the data required by API's.
All Builder classes should inherit from
This folder contains a builder and factory for managing HttpClients within the tests.
HttpRequestBuilder.csmanages creating the HttpRequest and also the HttpClient. This is only used within
HttpRequestFactory.csorchestrates the creation of the HttpRequest for each REST method.
This contains classes used to manage the configuration for the tests.
ConfigModel.csis a POCO representation of the json in
ConfigAccessor.cscontains the logic required to obtain the JSON from
appsettings.jsonand bind it to the
ConfigModel.csobject. This allows the configuration to be used as a simple object. The ConfigAccessor will automatically replace any configuration setting values with the values set in the Environment Variables on the machine running the tests.
appsettings.json we are using the configuration setting (key-value pair) "BaseUrl":"http://dev.azure.amidostacks.com/api/menu/". If there is an Environment Variable set on the current machine/build agent using
BaseUrl key, the value in
appsettings.json will be replaced.
These are POCO representations of entities that are used in API requests (E.g. Request body, response body). The builder classes are used to create instances of these models.
This is the parent folder for all test code
The "Fixtures" folder contains xUnit class fixtures. These class fixtures are used to create test context for the tests. The fixture is where you can put fixture setup (via constructor) and teardown (Via
See xUnit documentation for information on different fixtures and how to use them.
AuthFixture.cs contains methods for getting authentication tokens required in the test cases.
The Stories folder contains all the test cases (I.e. the BDDfy stories). Each class should represent a new test story, and within each class/story, there will be a number of test cases which test a specific feature.
Test cases within a story are defined using xUnit
Facts. BDDfy is used to describe and orchestrate the tests.
The solution tags tests as smoke tests using xUnit
This is where all the step definitions are created. The definitions contain the logic behind the tests and these steps are called from within the test cases found within the