This documentation provides a step-by-step guide for running tests for the Vogen project. This guide is designed for developers who are familiar with the project’s structure and requirements.

Overview of Testing Types

Vogen includes two distinct types of tests:

  1. Unit Tests: These tests validate the behavior of the Vogen codebase.
  2. Snapshot Tests: These tests ensure that the generated source code matches expected values.

Prerequisites

Before running tests, ensure you have the following in place:

  • A suitable C# development environment (e.g., Visual Studio or Visual Studio Code).
  • PowerShell is available on your machine to execute script files.
  • The project is built locally with a version of 999.9.xxx.

Running Unit Tests

You can run the unit tests either through your Integrated Development Environment (IDE) or by using the PowerShell script Build.ps1.

Running Tests in IDE

  1. Open your IDE (e.g., Visual Studio).
  2. Load the Vogen project solution (.sln).
  3. Locate the test project in the Solution Explorer. This can usually be found under tests/Vogen.Tests.
  4. Right-click on the project and select “Run Tests” or use the test explorer to execute all the tests.

Running Tests via PowerShell

To run the unit tests using PowerShell, follow these steps:

  1. Open PowerShell and navigate to the root directory of your Vogen project.

    cd path\to\vogen
    
  2. Execute the Build.ps1 script to start the testing process:

    .\Build.ps1
    

This command will build the solution and execute the unit tests. Monitor the output for any test failures or errors.

Running Snapshot Tests

To run the snapshot tests, you will utilize the provided script RunSnapshots.ps1.

Steps to Execute Snapshot Tests

  1. Open PowerShell and navigate to the root directory of your Vogen project.

    cd path\to\vogen
    
  2. Execute the snapshot tests script with the following command:

    .\RunSnapshots.ps1
    

The above command will run all snapshot tests defined in the codebase, comparing the generated source code against the expected outputs.

Example Code Snippets

The following is an illustration of a test case that might be found within the Vogen testing structure:

public class MyVo
{
    // Example value object definition
}

public class AnalyzerTests
{
    // A test within the AnalyzerTests suite
    public void Test_ExpectedBehavior()
    {
        // Arrange
        var myVo = new MyVo(...);
        
        // Act
        // Perform actions or assertions with myVo
        
        // Assert
        Assert.Equal(expectedValue, myVo.SomeProperty);
    }
}

This example demonstrates the setup of a value object (MyVo) and a test case within the AnalyzerTests class, showing an approach to validate behaviors.

Conclusion

Running tests for the Vogen project is streamlined through the use of PowerShell scripts and IDE capabilities. Both unit and snapshot tests can be executed easily to ensure that the code is functioning as expected. Please refer to the original source for further details and updates regarding the testing framework utilized within Vogen.

Source: docs/site/Writerside/topics/reference/FAQ.md, tests/Vogen.Tests/Vogen.Tests.csproj, docs/site/Writerside/topics/how-to/Testing.md