I have the problem that my unit tests always fail but there is no point at all. I set the label.visible values to true and query they for true. How can that be? I write the values in the console, they return false. But the method works in the program itself.
// GETTER/SETTER
internal void setlabeltest1Visible(bool xBool) { test1.Visible = xBool; }
internal bool getlabelTest1Visible { get { return test1.Visible; } }
internal void setlabeltest2Visible(bool xBool) { test2.Visible = xBool; }
internal bool getlabelTest2Visible { get { return test2.Visible; } }
// METHOD TO TEST
internal void switchLabelVisibility(bool xFlag)
{
test1.Visible = xFlag;
test2.Visible = xFlag;
}
// UNIT TEST
[TestMethod]
public void switchLabelVisibility_Test()
{
//Arrange
var ExportTests = new Export();
//Act //1. Fall - set visible values true
ExportTests.switchLabelVisibility(true);
//Assert
Assert.IsTrue(
ExportTests.getlabelTest1Visible &&
ExportTests.getlabelTest2Visible
); // FAILS (values false)
CodePudding user response:
Thx to @Steeeve, that works fine. :)
[TestMethod]
public void switchLabelVisibility_Test()
{
//Arrange
var ExportTests = new Export();
ExportTests.Visible = true; // this works!
//Act //1. Fall - Setze switchLabelVisibility true
ExportTests.switchLabelVisibility(true);
//Assert
Assert.IsTrue(
ExportTests.getlabelTest1Visible &&
ExportTests.getlabelTest2Visible);
}