Question

This question may be a bit nebulous, so please bear with me.

I am using Visual Studio, and I am new to the entire realm of unit testing. One thing I do a lot though is use Unit Testing as a quick and dirty ad-hoc "administration ui" at times when I need to just TRY things, but don't have time to make an actual admin system.

What I mean is ... sometimes I just want to get some data thrown into my database to see how it looks on a page. So I'll make a dirty unit test...

[Fact]
public void install_some_test_data(){
   using(var database = RavenDocumentStore()){
      using(var session = database.OpenSession()){
          // create some objects
          // add some objects
          // save some objects
      }
   }
}

Nowhere in here have I really cared about "testing", I just like the fact that I can right click and say "Run it" and it'll go, without launching up the program, without having to have a lot of interaction, etc. etc.

So my question is this;

Is this okay to do? I realize this isn't how a program should be long term managed, but I was scolded for doing this by another developer simply because I wanted to quickly show them how something they wanted to see worked. Is there really a problem with using these convenient tools as simpler ways of running commands against my database that can give me immediate feedback on whether it passed or failed?

My followup question to that is this; I have had to actually search pretty hard to find a unit test runner that lets me run individual methods instead of running every single unit test in a class. Is this normal? This whole thing kind of confuses me in general. Even when I do use tests for actually testing, why would I always want to run EVERY test every time? Isn't that extremely wasteful of time and resources? How do you control the order that they run in? This seems even more imperative when tests have to depend on some data to exist before they can run appropriately.

At the moment, I am using xunit and then the unit test runner in ReSharper, but out of the box, Visual Studio doesn't seem to let me run unit tests individually, just as huge batches in a single class.

Am I the only person confused by this?

Was it helpful?

Solution

Sure, it's actually very easy to execute a single unit test (without an external test runner required).

Go to TEST -> Windows -> Test Explorer

Now you'll see a window like this

enter image description here

Now you can rightclick on the test you want to execute and select 'run selected methods'.

As to your other question: it's hard to distinguish what you are asking. Are you demonstrating a proof of concept with a unit test? How does this test replace your admin panel?

OTHER TIPS

Just put your cursor on a Test function name. Then go to Test -> Run Selected Scope (or similar - the name changes by context). That test should execute and also create a test list for you automatically.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top