Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

C# How to Unit Test a Method that has multiple Inputs and Outputs?

I’ve been tasked to implement unit tests for a lot of modules in a firm and the only Problem I’ve encountered so far is for Methods where they have about 20 Input Variables and 15 Output variables. How do I even check for so many possibilities?

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Well, i guess then method looks something like this:

public Output Process(T1 input1, ..., T20 input20) { ... }

where Output would be

public class Output
{
    public OutputT1 Output1 { get; set; }
    ...
    public OutputT15 Output15 { get; set; }
}

So your test method could look like this:

[Fact]
public void TestProcessing()
{
    // Arrange
    var input1 = new T1(); // set some appropriate data
    ...
    var input20 = new T20(); // set some appropriate data

    // Also set expected values
    var actualOutput1 = new OutputT1();
    ...
    var actualOutput15 = new OutputT15();

    // Act
    var output = _sut.Process(input1, ..., input20);

    // Assert
    Assert.Equals(output.Output1, actualOutput1);
    ...
    Assert.Equals(output.Output15, actualOutput15);
}
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading