Databases Reference
In-Depth Information
When the new test project is created, you need to change it to add a reference to the
project under test, DataModel in this example. Another change you might want to make
is changing its root namespace to match the root namespace of the project under test.
Although for regular projects, it is a good idea to have the root namespace of the project
match the name of the assembly, for test projects such as the DateModel.Tests, changing
the root namespace to DataModel helps you avoid having to add extra using statements to
each file in the test project. The root namespace option can be changed using the project
properties window in Visual Studio.
The new test project is created with a single empty test file in it— UnitTest1.cs . A
test file contains a class, marked by the TestClassAttribute defined in the
Microsoft.VisualStudio.TestTools.UnitTesting namespace. A test class can define one
or more public methods marked with the TestMethodAttribute . These methods are the
actual tests . In other words, a single test file can have multiple tests in it.
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace DataModel
{
[ TestClass ]
public class UnitTest1
{
[ TestMethod ]
public void TestMethod1()
{
}
}
}
Also by convention, each test file, as well as the test class in it, is named with the name of
the class under test followed by the Test suffix, so a test class for the Product entity class
is called ProductTest . You can either rename the empty test file initially created from the
project template or simply delete it and add a new test to the project. You can do that
with the Add New Test dialog shown in Figure 8.6, which you can open by selecting
Add Æ New Test from the context menu of the test project in the Solution Explorer. In the
Add New Test dialog, unless you know the specific test template you need, it is best to
start with the Basic Unit Test.
Search WWH ::




Custom Search