1) What is the difference between
using NUnit.Framework;
and
using Microsoft.VisualStudio.TestTools.UnitTesting;
I am having a problem getting my tests to run. I create a new project in VS 2010 (File –> New Project –> Visual C# –> Test, and Visual Studio automatically creates some code for me:
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
//
}
}
}
I record my test using Selenium IDE, and I get:
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()
{
}
}
}
I am really confused when I am combining these two.
NUnit and MSTest (i.e. Microsoft.VisualStudio.TestTools.UnitTesting) are both unit testing frameworks. They both serve the same purpose; to let you define and run unit tests.
Selenium generates tests for NUnit out of the box. There is a plugin available that will generate tests for MSTest instead. I haven’t tried it yet, but it looks good. That would allow you to run your selenium tests easily within Visual Studio and TFS.
Alternatively you can download NUnit for free or get it with Nuget. Create a new class library project (not a test project) and add a reference to NUnit. Then add all the generated tests. If you want to run the tests within VS you’ll need a test runner like TestDriven.NET or you can use Resharper.