错误:在Winforms的单元测试中找不到“静态主目录”

时间:2018-11-22 05:55:06

标签: c# winforms unit-testing

我已经使用Winforms创建了Slave Simulator应用程序,并且不得不向其中添加单元测试项目。

我已经添加了单元测试项目,还添加了我的应用程序的正确引用。但是,当我运行测试用例时,出现了错误“程序不包含适合入口点的静态Main方法”。将输出类型更改为“ Windows应用程序”,并且我的应用程序中有一个Program.cs(包括main方法)。

以下是我编写的单元测试项目代码

public class UnitTest1
    {
        [TestMethod]
        public void TestCoilUpdateOperation()
        {
            UpdateCoilsToDataStore testObject = new UpdateCoilsToDataStore();
            bool actualStatus = testObject.UpdateCoils(UpdateCoilsToDataStore.TagName, UpdateCoilsToDataStore.ParameterNames, UpdateCoilsToDataStore.FunctionCode);
            bool expectedStatus = true;
            Assert.AreEqual(expectedStatus, actualStatus);
        }
    }

能帮我解决这个问题吗? 谢谢。

1 个答案:

答案 0 :(得分:3)

不要运行单元测试项目,这是类库项目,我们可以使用Text Explorer而不是整个项目来进行测试

从“测试”模板添加单元测试项目

enter image description here

创建单元测试项目后,编写您的单元测试。

[TestClass]
public class UnitTest1
{
    [TestMethod]
    public void TestMethod1()
    {
        //Your logic
        Assert.AreEqual(1, 1);
    }
}

构建项目,请不要运行它。

现在使用您的文本资源管理器来运行特定的测试。

enter image description here