atc-net / atc-rest-api-generator

A REST API code generator from OpenAPI Specification in YAML or Json file format
https://atc-net.github.io/repository/atc-rest-api-generator
MIT License
19 stars 4 forks source link

Add snapshot testing for generator modules with Verify #87

Closed TomMalow closed 3 years ago

TomMalow commented 3 years ago

This PR adds snapshot testing to the output of ATC Generator.

Snapshot testing is done through Verify package which is setup to take in a .yaml OpenApi spec file and generate a C# output file. The test setup currently only supports spec files that would generate a single file.

Currently the new test handles the following syntnx generators:

The Verify package uses two type of files to compare the snapshot.

Executing a single test that fails will open vs diff tool to compare between the .verified.cs and the .received.cs file.

Adding a new test

Adding a new test is done by simply adding a new openapi spec .yaml file to the relevant folder for a given syntax generator. This file will need to be reduced to only contain the minimal spec necessary to generate a single output file. Some of the test has additional asserts to verify that the spec.

The first time the test is run the test will fail and a .received.cs file is generated. The Verify package will fill your clipboard with a command line snippet to rename the received file to a verified file. This makes it a bit easier to add the output as a new base truth to compare against.

Updating all verified file

If a intentional change to ATC generator would change the output of multiple verified files, resulting in multiple failed test. Then a setting can be added to Verify setting to accept all new output and update all .verified.cs files. Add following line to VerifySettings setup in SyntaxGeneratorTestBase.cs

var settings = new VerifySettings();
settings.AutoVerify();

Remember to remove this again. Otherwise all changes will be accepted and not test will fail.

Additional

A tiny whitespace bug is also part of this PR.