【发布时间】:2020-03-23 22:37:30
【问题描述】:
我正在使用 vs 2019 社区并创建了一个名为 TestDLL 的类库 (.NET Framework) 项目。
该项目包含一个文件“TestDLL.cs”,其中包含作为命名空间的 TestDLL、一个名为 MyDll 的公共类和一个方法
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace TestDLL
{
public class MyDLL
{
static bool Opposite(bool input)
{
return !input;
}
}
}
在解决方案中,我添加了名为 UnitTest 的单元测试项目 (.NET Framework),添加了 TinyLib_dll.dll 作为参考,并创建了非常简单的测试。
using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace UnitTest
{
[TestClass]
public class UnitTest1
{
[TestMethod]
public void TestMethod1()
{
bool start = true;
bool result = MyDLL.Opposite(start);
Assert.AreNotEqual(start, result, "MyDll.Opposite failed");
}
}
}
当我尝试运行测试时,dll 文件编译成功,但 UnitTest 失败并显示“错误 CS0103 The name 'MyDLL' does not exist in the current context UnitTest”。
看起来虽然我引用了 dll 作为参考,但它并没有被加载到测试项目中。 有人可以帮帮我吗?
【问题讨论】:
标签: c# unit-testing dll