-1

我正在尝试运行一些测试,但是当我尝试时,测试永远不会完成,它卡在进行中,我可以阻止它的唯一方法是重新启动 VS,我用谷歌搜索,似乎找不到我在寻找。

[TestMethod()]
        public void fahrenheitToCelsiusBoilingTest()
        {
            float fahrenheit = 212F;
            float expected = 100F; // TODO: Initialize to an appropriate value
            float actual;
            actual = Form1.FahrenheitToCelsius(fahrenheit);
            Assert.AreEqual(Math.Round(expected, 2), Math.Round(actual, 2));
            //Assert.Inconclusive("Verify the correctness of this test method.");
        }
4

2 回答 2

2

可能是因为您错误地标记了测试:

对于 NUnit,

[TestMethod()]
public void fahrenheitToCelsiusBoilingTest()

..应该:

[TestFixture] // <-- Make sure you have this too!
public MyTestClass { 

    [Test]
    public void fahrenheitToCelsiusBoilingTest()

}

[TestMethod]是用于 MSTest 的标签,它是一个不同的测试框架;看到这个例如,快速比较。

更新:

然后确保您引用的是 NUnit:using NUnit.Framework;

如果您还没有 NUnit,请使用 Nuget 包管理器获取它:

去:View -> Other windows -> Package Manager Console,然后输入

PM> install-package nunit
于 2013-10-29T11:54:46.270 回答
0

您可以通过这种方式尝试您的代码,它将解决您的问题:

[TestFixture]
public class NUnitTests
{
    [Test]
    public void fahrenheitToCelsiusBoilingTest()
    {
            float fahrenheit = 212F;
            float expected = 100F; // TODO: Initialize to an appropriate value
            float actual;
            actual = Form1.FahrenheitToCelsius(fahrenheit);
            Assert.AreEqual(Math.Round(expected, 2), Math.Round(actual, 2));
            //Assert.Inconclusive("Verify the correctness of this test method.");
    }
 }
于 2013-10-29T12:00:02.440 回答