This documentation provides a step-by-step guide for running tests in the Vogen project. The project includes unit tests and snapshot tests to ensure the integrity and correctness of the codebase.

Running Unit Tests

To run the unit tests for Vogen, you have two options:

Option 1: Using Your IDE

  1. Open the Solution: Open the Vogen solution file in your preferred C# IDE (such as Visual Studio or Rider).

  2. Locate the Test Project: Navigate to the test project folder (tests/ConsumerTests/ or similar) in the solution explorer.

  3. Run the Tests:

    • In Visual Studio, you can use the Test Explorer to discover and run all tests. Ensure that the projects are built, and then click the Run All button.
    • In Rider, you can right-click on the test file or project and choose Run Unit Tests.

Option 2: Using PowerShell

  1. Open PowerShell: Start Windows PowerShell or a terminal that supports PowerShell commands.

  2. Navigate to Project Directory: Change your working directory to the root directory of the Vogen project.

    cd path\to\vogen
    
  3. Run the Build Script: Execute the Build.ps1 script to run all unit tests.

    ./Build.ps1
    

This command will execute the tests defined in the project, allowing you to confirm that everything is functioning as expected.

Running Snapshot Tests

Snapshot tests can be run separately to verify that the generated source code matches expected outputs. Follow these steps to execute the snapshot tests:

  1. Open PowerShell: As with unit tests, start Windows PowerShell or a compatible terminal.

  2. Navigate to Project Directory: Ensure you are in the Vogen project root directory.

    cd path\to\vogen
    
  3. Run the Snapshot Script: Execute the RunSnapshots.ps1 script to initiate the snapshot tests.

    ./RunSnapshots.ps1
    

This will compare the current generated code against previously saved snapshots, ensuring consistency and correctness in the code generation process.

Example Test Code

Unit Test Example

Here is a snippet of a unit test you might find in the project:

using Vogen.Tests.Types;

namespace ConsumerTests;

public class TryFromTests
{
    // Test methods will be defined here.
}

This code outlines the basic structure of a test within the ConsumerTests namespace. Additional test methods can be added to ensure thorough coverage of functionalities.

Snapshot Test Example

In the snapshot tests, you might encounter a class structure like this:

using System.Threading.Tasks;
using Shared;
using Vogen;

namespace SnapshotTests.GeneralStuff;

// contrib: An ideal place to start a new feature. Write a new test for the feature here to get it working, then
// add more tests. Move these tests if there are several of them, and it makes sense to group them.

This shows how you can structure snapshot tests, providing a foundation for new feature tests.

Conclusion

This guide has detailed how to run both unit tests and snapshot tests for the Vogen project using PowerShell and IDEs. Ensure that you follow the steps as outlined to maintain the quality and reliability of the codebase.

Source: docs/site/Writerside/topics/reference/FAQ.md