单元测试 - 方法测试失败 (labeltext.visible)

Unit Test - method tests failed (labeltext.visible)

我的问题是我的单元测试总是失败,但根本没有意义。我将 label.visible 值设置为 true 并查询它们是否为 true。怎么可能?我在控制台中写入值,它们 return false。但是该方法在程序本身中有效。

    // 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)

感谢@Steeeve,效果很好。 :)

[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);
}