AAF ― Applicita LTD
  • Getting Started
  • Development
    • Key Objectives
    • Development Environment & OS
    • Architecture
    • Visual Studio Solution
    • Setup for Local Development
      • Docker & Kubernates
      • Visual Studio Host Builder
  • Web
    • Feature
      • Authentication and Authorization
        • Sign up
        • Sign In
        • Sign out
        • Remember me
        • Recovering password
      • Tenant management
        • Create tenant
        • Search tenant
        • Tenant page
          • Change basic information
          • Change administrator
          • Change branding
          • Change style
          • Change status
          • Assets
        • Delete tenant
      • User management
        • Create user
        • Search user
        • Send email
        • User page
          • Editing page sections
          • Change basic information
          • Change profile picture
          • Change role
          • Change status
        • Delete user
        • Reset users password
      • Role management
        • Create role
        • Search role
        • Role page
          • Change basic information
          • Change status
          • Revoke role
          • Change permissions
          • Interactive permissions button
        • Delete role
      • Bug reporting
  • Testing
    • Testing Environment
    • Atata
    • Architecture
      • Feature structure
      • Common
        • Attributes
        • Components
        • Controls
        • Fixtures
        • Generators
    • Example
Powered by GitBook
On this page

Was this helpful?

  1. Testing
  2. Architecture
  3. Common

Generators

PreviousFixturesNextExample

Last updated 5 years ago

Was this helpful?

Often, we need to create some test data that we will use in multiple tests, like a test user, or we need to create multiple test users and keep track so that we can dispose of them once tests are complete.

This is why we use generators to keep track of all created entities in a list, maybe keep track of last created object, and in similar situations where we can iterate through that list and eventually dispose of created objects.

We use generators in for different tests, where we can create test data in method, and dispose of this test data in method when all tests finish executing.

Here is a snippet of how UserGenerator is used in UserSetupFixture

[SetUpFixture]
[Parallelizable(ParallelScope.Fixtures)]
public class UserSetupFixture
{
    public DriverService DriverService { get; } = new DriverService();

    [OneTimeSetUp]
    public void Init()
    {
        DriverService.CreateOrReuseDriver();
        try
        {
            CreateTestData(UserGenerator.GenerateTestUser());
        }
        catch (Exception e)
        {
            UserGenerator.TestUser.Delete();
            Cleanup();

            throw new Exception("Failed to create test data for users feature testing", e);
        }
    }

    [OneTimeTearDown]
    public void UserFixtureTearDown()
    {
        if (UserGenerator.Users.Any())
        {
            DriverService.CreateOrReuseDriver();
            try
            {
                UserGenerator.Users.ForEach(u => DeleteUser(u.Identifier));
            }
            catch (Exception e)
            {
                throw new Exception("User cleanup failed.", e);
            }
            finally
            {
                Cleanup();
            }
        }
    }
}
SetupFixtures
OneTimeSetup
OneTimeTeardown
Generators section