views:

69

answers:

3

Is there a strick one-to-one correspondence with a test in VS and a method? In the end, it's just code, right?

I'd love to run-time generate separate tests based on data input.

I realize I could just have one test that loops through my data and performs all of the desired operations, but I'd rather have each item be represented by an individual test.

This is super straight-forward in Ruby-based test solutions.

...so I'm curious.

Clarification: A method marked as [TestMethod] gets special love in reporting. Can I generate this special love without a method for each? How?

+1  A: 

I haven't used Microsoft's test system myself, but nothing I've read about it suggested you're limited to one test per production method - and it would be completely broken for it to make such a restriction. I would find it very hard to believe that were the case.

I believe that if you generate test cases automatically given your production class, VS will generate a single test method per production method by default - but there's nothing that says you can't change these completely. (And of course if you're doing TDD you wouldn't start with the production class anyway.)

In case you were talking about "does every method in a test class have to be a test" - no. That's what the [TestMethod] attribute is for.

Jon Skeet
+1  A: 

A test is a collection of methods which exercise (aka "Test") your code.

Generally you target each method in your test unit to perform exactly one kind of test.

The reality is that it is sometimes very difficult to test individual pieces of your code without invoking other pieces that might also have a test method run against them.

To help, you have methods that fire as part of the unit to setup and tear down the testing framework. Those exist to get your app in a position to run the one or more test methods.

Unit Tests can also items such as excel or csv files to hold the data to test against. Depending on the result you'll assert a pass or fail.

Which brings us to the final answer: yes, it's just code... Code that has the ability to report back to the Microsoft testing framework.

Chris Lively
A: 

Have you looked at Fitnesse for data based testing?

Christopherous 5000