Mark Struzinski
Mark Struzinski

Reputation: 33491

What is the best way to store static unit test variables?

I am currently using NUnit and testing a class library. Up until now, I have used a list of constants at the top of the test class to hold some static test variables. Is this the best way to do this, or is there a more fluent way to handle it?

Upvotes: 1

Views: 417

Answers (2)

user25788
user25788

Reputation: 61

Whenever I can, I store data externally in an xml file that we check into source control.

Upvotes: 1

Jon Skeet
Jon Skeet

Reputation: 1503210

By "static test variables" do you actually mean constants (whether genuine constant, immutable instances or just ones you don't change)? I use those frequently, and just put them at the top of the test class.

If there are several related test classes, it can be handy to separate out common values into a different class though. (It could act as your base class, but I'm not terribly fond of using inheritance just to get access to things more easily. Java static imports are handy there...)

Upvotes: 3

Related Questions