问题描述:

I want to to create a custom TestRunner which allow to run unit test for following unit framework:

  • MSTest
  • NUnit
  • xUnit

This custom Test Runner should have posibility to define criteria to run test. For example:

  • run specific test method (by name)
  • run test methods for specific tested method
  • run test methods for specific tested class

I've found solution for NUnit and in xUnit I should implement ITestRunner. But do you know how I can run tests from code for MSTest?

Do you know how I can define criteria to run only method which filled criteria defined above?

网友答案:

You can try Fixie (still under development). It allows you to write custom conventions to determine what is considered a test regardless of the unit testing framework used. For example, you can write one convention that identifies all void public methods in classes ending with "Tests" as unit tests regardless of attributes and so on (in fact, this is its default convention). It is very flexible. To write a custom convention, you need to implement the Convention class in your assembly and Fixie will discover it. Read it's documentation for more information and see the excellent samples and tests included in the project.

It is already integrated with visual studio through TestDriven.net. If you don't have that then you'll need to run it through its console runner.

网友答案:

Thanks for replying to my comment. I think I can suggest you a possible solution, and I haven't tried this by myself. But I believe this is do-able. This suggesion is more of a programtic approach mixed with some built-in command line options provided by each test framework you mentioned (NUnit, MSTest, xUnit).

If all of these test frameworks have the ability to execute tests, whether it is selectively, as a group, or as an entire test suite by the command line, you can always use Console App, with predefined parameters to execute these tests as you desired.

As far as I know all of these test frameworks provides command line test runners and options. But they can be differed based on the options they provide.

First thing is to analyse each of these test framework's ability provide command line arguments so you can execute tests as you desired.

MSTest.exe Command Line provide some options you might want to look into.

  • /test

  • /Category

Are some of the options you can look into.

NUnit console also provide some options. But I haven't looked into this much yet.

XUnit has a Console Test runner which you can look into more (i.e xunit.console MyTestLibrary.dll).

It is important to note that, both xUnit.NET and NUnit are extensible. So if you don't have the options you need, you can look at extending what has provided by the framework. Even go down the path that creating your own console runner is not that hard. Un-like MSTest, both of these frameworks are open source so you can see the options they have provided. Given that running tests selectively is a key requirement I would imagine that these frameworks have built-in options and you don't have to do much customizations.

Once you have identified abilities of these framework's Console counterparts, you can then proceed on creating your client app/console app, which you can specify the tests to run selectively. This client app would feed tests selectively to each runner and execute Console.exe's. This should run your tests selectively and accordingly. You can further automate this by providing some sort of a configurable metadata/manifest file. For example you can specify variety of tests to run from a metadata or manifest file, and your console runner would read from the metadata files.

Based on your client app configuration, if it is a Console app, you can also invoke via the build system.

Hope this would point you to a direction what you want to achieve.

相关阅读:
Top