开发者

ASP.NET unit testing: where to create/delete test user accounts?

开发者 https://www.devze.com 2023-03-12 00:51 出处:网络
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/dr

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消