5

I like the convenience of test runners to run a single test method. Is there a way to run any method without making it a test?

The reason being I'm tired of writing Console apps with a CLI menu or a Windows Form with a button per method only for the sake of running various utility code that doesn't need to be realized in a UI. A parameterized Console app is too much effort too.

I have multiple methods. They don't rely on each other. Each completes a task that I as a developer run.

Ideally I'd like to have a Visual Studio .csproj file with classes of individually runnable methods that would not be picked up by the test framework, but that I could choose to run from a tool like a test runner.

John K
  • 28,441
  • 31
  • 139
  • 229

1 Answers1

4

You can just do a method invocation in the Interactive Window in Visual Studio. You'll need type the fully qualified name out, like MyNamespace.MyType.MyMethod("some-arg"). If it's not static then you'll need to new it up first of course.

If you want more convenience and don't mind paying for it then ReSharper has the ability to right click and run/debug static methods . Alive also has this feature.

Finally, if you want to use a test runner, but don't want these to be run with your "regular" tests, NUnit has the Explicit attribute, which means the tests only run when you explicitly run them. Other testing frameworks have concepts that are close.

Stuart
  • 5,358
  • 19
  • 28
  • Thanks for this suggestion. But for some reason my ReSharper does not show a Debug context action in the light bulb menu. Method is public and static void so should be working according to the docs. Would you have any tips on how to make it appear? – AlexVPerl Aug 27 '21 at 21:34