【问题标题】:Need help understanding Assembly references需要帮助理解程序集参考
【发布时间】:2011-05-31 20:40:36
【问题描述】:

1) 有什么区别

using NUnit.Framework;

using Microsoft.VisualStudio.TestTools.UnitTesting;

我在运行测试时遇到问题。我在 VS 2010 中创建了一个新项目(文件 --> 新项目 --> Visual C# --> 测试,Visual Studio 会自动为我创建一些代码:

using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace TestProject1
{
/// <summary>
/// Summary description for UnitTest1
/// </summary>
[TestClass]
public class UnitTest1
{
    public UnitTest1()
    {
        //
        // TODO: Add constructor logic here
        //
    }

    private TestContext testContextInstance;

    /// <summary>
    ///Gets or sets the test context which provides
    ///information about and functionality for the current test run.
    ///</summary>
    public TestContext TestContext
    {
        get
        {
            return testContextInstance;
        }
        set
        {
            testContextInstance = value;
        }
    }

    #region Additional test attributes
    //
    // You can use the following additional attributes as you write your tests:
    //
    // Use ClassInitialize to run code before running the first test in the class
    // [ClassInitialize()]
    // public static void MyClassInitialize(TestContext testContext) { }
    //
    // Use ClassCleanup to run code after all tests in a class have run
    // [ClassCleanup()]
    // public static void MyClassCleanup() { }
    //
    // Use TestInitialize to run code before running each test 
    // [TestInitialize()]
    // public void MyTestInitialize() { }
    //
    // Use TestCleanup to run code after each test has run
    // [TestCleanup()]
    // public void MyTestCleanup() { }
    //
    #endregion

    [TestMethod]
    public void TestMethod1()
    {
        //
        // TODO: Add test logic here
        //
    }
}
}

我使用 Selenium IDE 记录我的测试,我得到:

using System;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;
using NUnit.Framework;
using Selenium;

namespace SeleniumTests
{
[TestFixture]
public class Untitled2
{
private ISelenium selenium;
private StringBuilder verificationErrors;

[SetUp]
public void SetupTest()
{
selenium = new DefaultSelenium("localhost", 4444, "*chrome", "http://localhost/km/pldefault.aspx");
selenium.Start();
verificationErrors = new StringBuilder();
}

[TearDown]
public void TeardownTest()
{
try
{
selenium.Stop();
}
catch (Exception)
{
// Ignore errors if unable to close the browser
}
Assert.AreEqual("", verificationErrors.ToString());
}

[Test]
public void TheUntitled2Test()
{
}
}
}

当我将这两者结合起来时,我真的很困惑。

【问题讨论】:

    标签: c# selenium


    【解决方案1】:

    你有充分的理由感到困惑! ;-) 这是两个完全独立的库,解决(或多或少)相同的问题。两者都是单元测试库,就像所有可用的 xUnit 库一样。 Visual Studio 通常使用它内置的单元测试库来创建测试项目。 Selenium 为另一个库生成测试:NUnit。这是一个免费的替代方案。所以如果你想使用 Selenium 生成的测试,你应该从一个类库项目开始。只需添加对 NUnit 的引用,添加生成的代码就可以了。

    【讨论】:

      【解决方案2】:

      NUnit 和 MSTest(即 Microsoft.VisualStudio.TestTools.UnitTesting)都是单元测试框架。它们都具有相同的目的;让您定义和运行单元测试。

      Selenium 为 NUnit 生成开箱即用的测试。 There is a plugin available 将为 MSTest 生成测试。我还没有尝试过,但它看起来不错。这将允许您在 Visual Studio 和 TFS 中轻松运行 selenium 测试。

      您也可以免费download NUnit 或通过Nuget 获取。创建一个新的类库项目(不是测试项目)并添加对 NUnit 的引用。然后添加所有生成的测试。如果你想在 VS 中运行测试,你需要像 TestDriven.NET 这样的测试运行器,或者你可以使用 Resharper

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2012-09-01
        • 1970-01-01
        • 1970-01-01
        • 2013-04-18
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多