Visual Studio "Run a method" vs "Utility tests"
I use XUnit and Resharper to run my tests. In a given project I usually have a few utility tests which are not really tests but exist purely so I can execute a bit of code easily开发者_JAVA百科. For example, I have a test which outputs my NHibernate mappings (I use Fluent NHibernate) to a temporary directory. I don't really like having these as tests, is there a better way to simply "run a method" other than use a testrunner?
If you have a TestDriven.net then all you have to do is to just click on the method and it will run. You don't have to decorate the method with Test
or TestMethod
attribute or something like that.
testdriven.net has a personal edition, which is free.
If your test runner is going to insist on you have a marker attribute on a method for you to be able to execute it, all you can do is follow that requirement. (As the other answer says, TD.NET works with you on this)
So, assuming you're going to need to have a FactAttribute
-derived class of some kind in the picture, the next interception point is to dynamically cause the task to be Skip
ped at runtime a la my examples in this xUnit.net feature request
For instance, you could walk the process tree and determine if you're indirectly invoked by devenv.exe, or check for an environment variable before running. Perhaps Resharper sets an environment variable to indicate that it's the runner? (TeamCity [from the same authors as R#] sets an enviroment variable - see the xunit MSBuild task in the source code for the details.)
精彩评论