Learning to Use xUnit.Net (1 of 3)

Learning to Use xUnit.Net (2 of 3)

I started using xUnit.Net a few weeks ago. My first question was how to do the things I was used to do in other testing frameworks like MSTest or NUnit, especially when using this framework for unit testing and for higher level tests like Selenium RC web tests. Here’s how I went about it.

I am going to show some scenarios I have run to convert MSTest to xUnit.Net having the following class,

Running the Tests (CLASSINITIALIZE – CLASSCLEANUP)

Note that SeleniumWebTestContext is holding information about Selenium RC and starts the server.

ClassInitialize – ClassCleanup / IUseFixture

Sometimes we require sharing information among the methods defined in a class. For example, in web tests, we want to share the logged in user’s information, execute different actions and validations and log out at the end.
Converting MSTest ClassInitialize and ClassCleanup to the equivalent implementation in xUnit.Net will look like the following class:

IUseFixture is used to pass information shared by the tests, in this case information selenium’s logged user. The LoggedUserContext class will look like this,

In my next post I will show a solution for implementing an equivalent MSTest TestCategory attribute in xUnit.Net.

Focus Mode

Contact Request

Close

We will call you right away. All information is kept private