MSTest Project with Nunit Tests - Recognition

Asked by Jamie Clayton

As a result of an issue with how Nunit and breakpoint debugging works with VS2010, I modified all the classes in my Nunit project to include allow side by side Nunit/MSTest code. I can then use my Nunit code in MSTest by just changing a build flag. It allows me to compile and use the MS test integrated GUI features and have Nunit tests (good from the CI server) all in the same project. I thought this was the best of both TDD worlds (although some of my Nunit tests need to be dumbed down to suit the MSTest implementation).

The one downside to this change is the VS project file changes. To allow MSTests to run you have to modify your Nunit project to include the MSTest Project Type Guids.

<ProjectTypeGuids>{3AC096D0-A1C2-E12C-1390-A8335801FDAB};{F184B08F-C81C-45F6-A57F-5ABD9991F28F}</ProjectTypeGuids>

Now it would be really cool if the Nuit GUI and Consoles applications would also check these project types and run nunit tests if they existed in those projects, so my CI server doesn't need to rip this <ProjectTypeGuids> entry out of my project build the file and then restore the Nunit project file to get Nunit tests running. Could Nunit be upgraded to include these MSTest projects?

I notice there is an addin to VS2010 which does this for you at, but it will not help me with my CI server.
http://visualstudiogallery.msdn.microsoft.com/en-us/c8164c71-0836-4471-80ce-633383031099

VB Code required for Nunit/MSTest integrated tests (just add a Compile Constant to the project like NUNIT=TRUE)
#Region "Nunit and MSTest Duel Use"
#If NUNIT Then
Imports NUnit.Framework
' Convert the MS Test Attributes to Nunit versions
Imports TestClass = NUnit.Framework.TestFixtureAttribute
Imports TestMethod = NUnit.Framework.TestAttribute
Imports TestCleanup = NUnit.Framework.TearDownAttribute
Imports TestInitialize = NUnit.Framework.SetUpAttribute
Imports ClassCleanup = NUnit.Framework.TestFixtureTearDownAttribute
Imports ClassInitialize = NUnit.Framework.TestFixtureSetUpAttribute

#Else
Imports Microsoft.VisualStudio.TestTools.UnitTesting
' Convert the Nunit attributes to the MS Test versions
Imports TestFixture = Microsoft.VisualStudio.TestTools.UnitTesting.TestClassAttribute
Imports Test = Microsoft.VisualStudio.TestTools.UnitTesting.TestMethodAttribute
Imports Category = Microsoft.VisualStudio.TestTools.UnitTesting.TestCategoryAttribute
Imports Setup = Microsoft.VisualStudio.TestTools.UnitTesting.TestInitializeAttribute
Imports TestFixtureSetUp = Microsoft.VisualStudio.TestTools.UnitTesting.ClassInitializeAttribute
Imports TestFixtureTearDown = Microsoft.VisualStudio.TestTools.UnitTesting.ClassCleanupAttribute
#End If

Imports NUnitAssert = NUnit.Framework.Assert
Imports MsAssert = Microsoft.VisualStudio.TestTools.UnitTesting.Assert
#End Region

#Region "Fixture Setup"

#If Not Nunit Then
    Private _testContextInstance As TestContext

    '''<summary>
    '''Gets or sets the test context which provides
    '''information about and functionality for the current test run.
    '''</summary>
    Public Property TestContext() As TestContext
        Get
            Return _testContextInstance
        End Get
        Set(ByVal value As TestContext)
            _testContextInstance = value
        End Set
    End Property
#End If

    Public Sub New()
        MyBase.New()
    End Sub

    <Setup()> Public Sub Init()
    End Sub

#If NUNIT Then
    <TestFixtureSetUp()> Public Shared Sub Setup()
#Else
    <ClassInitialize()> Public Shared Sub Setup(ByVal testContext As TestContext)
#End If
    End Sub

    <TestFixtureTearDown()> Public Shared Sub Finish()
    End Sub

#End Region

Question information

Language:
English Edit question
Status:
Answered
For:
NUnit V2 Edit question
Assignee:
No assignee Edit question
Last query:
Last reply:
Revision history for this message
Charlie Poole (charlie.poole) said :
#1

There is nothing in NUnit that looks at VS project types.
NUnit is completely independent of Visual Studio with
a single exception: it understands the format of a VS
project file and can extract the assembly paths from it.

So, unfortunately, the question of having NUnit check
certain project types doesn't even come up, since
NUnit is actually dealing with the compiled assembly
rather than the VS project.

This may be better brought up on the nunit-discuss list,
where more folks could contribute ideas or approach
the problem from a different angle.

Charlie

On Sun, Sep 12, 2010 at 8:07 AM, Jamie Clayton
<email address hidden> wrote:
> New question #125086 on NUnit V2:
> https://answers.launchpad.net/nunitv2/+question/125086
>
> As a result of an issue with how Nunit and breakpoint debugging works with VS2010, I modified all the classes in my Nunit project to include allow side by side Nunit/MSTest code. I can then use my Nunit code in MSTest by just changing a build flag.  It allows me to compile and use the MS test integrated GUI features and have Nunit tests (good from the CI server) all in the same project. I thought this was the best of both TDD worlds (although some of my Nunit tests need to be dumbed down to suit the MSTest implementation).
>
> The one downside to this change is the VS project file changes.  To allow MSTests to run you have to modify your Nunit project to include the MSTest Project Type Guids.
>
> <ProjectTypeGuids>{3AC096D0-A1C2-E12C-1390-A8335801FDAB};{F184B08F-C81C-45F6-A57F-5ABD9991F28F}</ProjectTypeGuids>
>
> Now it would be really cool if the Nuit GUI and Consoles applications would also check these project types and run nunit tests if they existed in those projects, so my CI server doesn't need to rip this <ProjectTypeGuids> entry out of my project build the file and then restore the Nunit project file to get Nunit tests running.  Could Nunit be upgraded to include these MSTest projects?
>
> I notice there is an addin to VS2010 which does this for you at, but it will not help me with my CI server.
> http://visualstudiogallery.msdn.microsoft.com/en-us/c8164c71-0836-4471-80ce-633383031099
>
> VB Code required for Nunit/MSTest integrated tests (just add a Compile Constant to the project like NUNIT=TRUE)
> #Region "Nunit and MSTest Duel Use"
> #If NUNIT Then
> Imports NUnit.Framework
> '   Convert the MS Test Attributes to Nunit versions
> Imports TestClass = NUnit.Framework.TestFixtureAttribute
> Imports TestMethod = NUnit.Framework.TestAttribute
> Imports TestCleanup = NUnit.Framework.TearDownAttribute
> Imports TestInitialize = NUnit.Framework.SetUpAttribute
> Imports ClassCleanup = NUnit.Framework.TestFixtureTearDownAttribute
> Imports ClassInitialize = NUnit.Framework.TestFixtureSetUpAttribute
>
> #Else
> Imports Microsoft.VisualStudio.TestTools.UnitTesting
> '   Convert the Nunit attributes to the MS Test versions
> Imports TestFixture = Microsoft.VisualStudio.TestTools.UnitTesting.TestClassAttribute
> Imports Test = Microsoft.VisualStudio.TestTools.UnitTesting.TestMethodAttribute
> Imports Category = Microsoft.VisualStudio.TestTools.UnitTesting.TestCategoryAttribute
> Imports Setup = Microsoft.VisualStudio.TestTools.UnitTesting.TestInitializeAttribute
> Imports TestFixtureSetUp = Microsoft.VisualStudio.TestTools.UnitTesting.ClassInitializeAttribute
> Imports TestFixtureTearDown = Microsoft.VisualStudio.TestTools.UnitTesting.ClassCleanupAttribute
> #End If
>
> Imports NUnitAssert = NUnit.Framework.Assert
> Imports MsAssert = Microsoft.VisualStudio.TestTools.UnitTesting.Assert
> #End Region
>
>
>
> #Region "Fixture Setup"
>
> #If Not Nunit Then
>    Private _testContextInstance As TestContext
>
>    '''<summary>
>    '''Gets or sets the test context which provides
>    '''information about and functionality for the current test run.
>    '''</summary>
>    Public Property TestContext() As TestContext
>        Get
>            Return _testContextInstance
>        End Get
>        Set(ByVal value As TestContext)
>            _testContextInstance = value
>        End Set
>    End Property
> #End If
>
>    Public Sub New()
>        MyBase.New()
>    End Sub
>
>    <Setup()> Public Sub Init()
>    End Sub
>
> #If NUNIT Then
>    <TestFixtureSetUp()> Public Shared Sub Setup()
> #Else
>    <ClassInitialize()> Public Shared Sub Setup(ByVal testContext As TestContext)
> #End If
>    End Sub
>
>    <TestFixtureTearDown()> Public Shared Sub Finish()
>    End Sub
>
> #End Region
>
>
> --
> You received this question notification because you are an answer
> contact for NUnit V2.
>

Can you help with this problem?

Provide an answer of your own, or ask Jamie Clayton for more information if necessary.

To post a message you must log in.