Jay Pete
Jay Pete

Reputation: 4247

C# Unit tests based on unknown number of json files

I would like to create test suite based on the tests defined in this repo:

https://github.com/json-schema/JSON-Schema-Test-Suite

The tests are defined in a number of json files, that can contain any number of tests.

Obviously I don't want to write a test for each test defined in this repo, I want to auto discover the tests and run them. But I would like to use a standard unit test framework like NUnit or xUnit. But if I just loop through all the files in a single test, then I don't get much info out of that. It will just be a single test that fails or passes in Jenkins or Team City. I could of course output all the relevant data, but that isn't nice.

Is there a way to make each test show up as a single unit test when running my test suite, without having to actually write each test method?

EDIT: I guess what I am looking for is something like xUnit ClassData like described here Pass complex parameters to [Theory]. But then my next question would be if I can have each test show up with different names ;)

What I needed to search for on Google was "data driven unit tests".

Upvotes: 1

Views: 765

Answers (2)

Jay Pete
Jay Pete

Reputation: 4247

NUnit TestCaseSource does exactly what I want it to.

@Kieren Johnstone I would prefer not doing code generation. I considered that and decided against it for the sake of simplicity.

Upvotes: 1

Kieren Johnstone
Kieren Johnstone

Reputation: 41993

You could generate code using T4 templates or some other automatic means. The massive advantage here is that the tests themselves are already in a decent data structure (you couldn't line things up better than that!).

Upvotes: 0

Related Questions