测试Web API控制器?

KJ3*_*KJ3 0 .net c# unit-testing asp.net-web-api

我真的没有使用单元测试的经验,但是我试图在我的应用程序中实现一个非常简单的测试,并且不能让它运行.我有一个.NET Web API,带有我想测试的控制器.我在一个单独的项目中创建了以下测试类,并在其中引用了API:

[TestClass]
class TestWebhookControllers
{
    [TestMethod]
    public void TestTest_ShouldReturn201()
    {
        var controller = new TestWebhookController();
        controller.Request = new HttpRequestMessage();
        controller.Configuration = new HttpConfiguration();

        var result = controller.Get();

        Assert.AreEqual(result.StatusCode, HttpStatusCode.Continue);
    }
}
Run Code Online (Sandbox Code Playgroud)

当我点击运行所有测试时,构建成功但没有其他事情发生.测试资源管理器为空.没有任何错误.我必须遗漏一些基本的东西.

TGH*_*TGH 5

我认为你需要将这个课程公之于众

[TestClass]
public class TestWebhookControllers
Run Code Online (Sandbox Code Playgroud)