I am new in unit testing. I want to unit test my ASP.NET/MVC application using built-in MS Test.
To perform many tests i need to use temporary user accounts. Where is the best place to put creating/dropping code? I tried to create users in [TestInitialize()] method and put result开发者_JAVA百科s of type User into class field but it doesnt remain to the moment of the second test s starting :( Or should i create temp user account in every test method? This doesntlook well... Thank you!I would normally generate the user accounts into a property of the test during the method with the attribute setup, and delete them in the method marked teardown
public UserAccount account { get; set; }
[SetUp]
public void SetUp
{
// Set up your accounts here
}
[TearDown]
public void TearDown()
{
account.Delete();
}
The attributes ensure that these fixtures are run before and after the test methods.
精彩评论