Strange behaviour converting tests from NUnit to VSTS  
Author Message
Orest





PostPosted: Visual Studio Performance Tools (Profiler), Strange behaviour converting tests from NUnit to VSTS Top

I am converting NUnit tests to VSTS tests and came upon the following problem.
I have some class that acts as a base classs for all my tests

[TestFixture]
internal abstract class BaseTest
{
    [TestFixtureSetUp]
    public void Init()
    {
       // Some init method for all tests inside test fixture...
    }
    ...
}


and some test class

[TestFixture]
public class SomeTest : public BaseTest
{
    [Test]
    public void SomeTestMethod()
    {
        ...
    }
    ...
}


When I run SomeTestMethod using NUnit framework, Init method from the base class is called first and then my actual test method. This is the expected behaviour. For the conversion of my unit tests into VSTS compatible ones I had to replace TestFixture attribute with the TestClass attribute, TestFixtureSetUp with the ClassInitialize and Test with the TestMethod. Also I had to change the signature of my Init method:

public static void Init(TestContext ctx)

But now when I run SomeTestMethod from the VSTS, my Init method from the base class does not get called. Is there some workaround for such a behaviour Thanks.


Visual Studio Team System16  
 
 
Eric Jarvi MSFT





PostPosted: Visual Studio Performance Tools (Profiler), Strange behaviour converting tests from NUnit to VSTS Top

The easiest workaround that comes to mind would be to add the explicit call to Init as the first thing you do inside of SomeTestMethod, since it is apparently no longer automagically invoked.


 
 
Dmitry Vorobyev





PostPosted: Visual Studio Performance Tools (Profiler), Strange behaviour converting tests from NUnit to VSTS Top

It's not nice to call an initialization method from a "work" method. Also, a test class normally includes much more than the only SomeTestMethod, usually there are tens or hundreds of test methods. So from what method to call Init

It's obviously a framework bug since ClassInitializationAttribute is not marked as "not inheritable". So it should be valid in inherited classes as well. Too bad.



 
 
Carl Daniel





PostPosted: Visual Studio Performance Tools (Profiler), Strange behaviour converting tests from NUnit to VSTS Top

Does making Init in the base class virtual and overriding it in the derived class with a simple forwarding call to the base class solve the problem

It does sound like a bug - I'd suggest that the original asker open a bug report on Connect:

http://connect.microsoft.com/feedback/default.aspx SiteID=210