I'm creating a unit test for an existing project.
n1
andn2
are input numbersop
is operands in a switch case in the main program
The problem is with actual
. I cannot match the expected and actual value because I get the error cannot implicitly convert void to int
.
My unit test:
[TestMethod()]
public void docalcTest(int actual)
{
Form1 target = new Form1(); // TODO: Passenden Wert initialisieren
double n1 = 15; // TODO: Passenden Wert initialisieren
double n2 = 3; // TODO: Passenden Wert initialisieren
int op = 2; // TODO: Passenden Wert initialisieren
int expected = 5;
actual = target.docalc(n1, n2, op);
Assert.AreEqual(expected,actual);
}
The code for docalc:
public void docalc(double n1, double n2, int op)
{
result = 0;
setText("clear");
switch (op)
{
case 1:
result = n1 + n2;
break;
case 2:
result = n1 - n2;
break;
case 3:
result = n1 * n2;
break;
case 4:
result = n1 / n2;
break;
}
setText(result.ToString());
}