0

I have C# API Library (.Net Framework 4.5.2) and I want to create regression tests to compare between 2 versions of the API. All the information that I found is about how to create regression tests for Restful API, which is not my case.

Today, I have a project that loads 2 versions of that API with a different alias name. For example:

  1. The production version is loaded from nuget.
  2. The development is loaded from the solution.

Advantages of this approach:

  1. It's very easy to debug when there is a difference (Unlike comparing a file with many data from different classes or properties)
  2. I have compile-time errors (Unlike using reflection)

There is 2 big disadvantage for this approach which makes it hard to maintain:

  1. There is a lot of code duplication. (I need to write the same code for each API version)
  2. I need to write the full namespace of each class in order to use it.

Is there a better way to do it? Or there is any tool or framework that do it?

Example of what I have today:

extern alias devVer;

using devVerApi = devVer::ApiLibrary;
using prodVerApi = ApiLibrary;

[TestMethod]
public void ClassWithSomeLogicTests_CheckRegression()
{
    var prodClass = new prodVerApi.ClassWithSomeLogic("Text");
    var devClass = new devVerApi.ClassWithSomeLogic("Text");

    Assert.AreEqual(prodClass.GetLength(), devClass.GetLength());
}
itaiy
  • 1,152
  • 1
  • 13
  • 22
  • 1
    `All the information that I find is about Restful API` what did you *search* for? And what is the question? Regression tests mean one thing, comparing the API exposed by a library and detecting changes is completely different. That's essentially diff-ing two libraries – Panagiotis Kanavos Jun 25 '19 at 09:09
  • 1
    If you want to compare two libraries the easy way is to retrieve all types and their members using Reflection and compare them. A quick&dirty way would be to write them out to two different files then use a diff tool with block detection to find the changes – Panagiotis Kanavos Jun 25 '19 at 09:10
  • Rather than comparing changes, may I suggest that you create tests with set (hardcoded) inputs and assert that they're equal to the expected output. That way, you can do changes and each time run all tests and confirm that nothing is broken. You wouldn't need to compare one build against another but you can run them as you go along. – Mark Cilia Vincenti Jun 25 '19 at 09:11
  • Let me be more clear. When I do changes in my API, I want to check that I didn't break anything. In order to do it, I have unit tests, integration tests against expected output (Created only once) and I compare the output of the new API against the previous API version on real data from the production. The question is about the last one. Maybe regression is not the correct definition of these tests. – itaiy Jun 25 '19 at 09:18
  • @PanagiotisKanavos I have edited my question with answers to your questions. – itaiy Jun 25 '19 at 09:40

0 Answers0