Unit testing a static class with a private static field that is a common dependency

I have a public static class I'm trying to unit test using Visual Studio 2012's built in testing framework. When I try to run unit tests on it I get this error:

The type initializer for 'Foo.Bar.Controllers.DataService' threw an exception. 

the inner exception says:

 {"Value cannot be null.\r\nParameter name: value"}
  at System.Boolean.Parse(String value)

The class I'm trying to test is:

namespace Foo.Bar.Controllers {

    public static class DataService {
        private static ClassINeedOneInstanceOf _dataGettingClass = new ClassINeedOneInstanceOf();

        public static List<Info> GetServiceInfoList(String svcName) {
            List<Info> infoList = null;
            if (ERROR CHECKING AND STUFF) {
                infoList = _dataGettingClass.GetInfoFromAwesomeOtherService(svcName);
            return infoList

        // other methods like the one above that return data for other things and in different ways but they
        // are all public static, return data, and use a method from _dependecyGettingClass

My understanding of static classes with static fields is that the first time the class is called the field instantiates and can be used from then on. This is backed up by my code actually working, ex: the website uses it to get data and such

Is the unit test framework doing something weird and not calling the class in the same way as "typical" c# code does? If so, is there a way I can change the mstest code?

Also, with this use pattern is my code architecture and design correct? Should this class (with its reliance on one instance of _dataGettingClass) be written differently?


Edit: The unit test class that calls the method is:

namespace Foo.Test
    public class DataServiceTests

        public void GetInfoListUsingServiceName()
            string serviceName = "service001";
            var result = DataService.GetServiceInfoList(serviceName);


and the line that is reference by the parse inner exception is:

private static ClassINeedOneInstanceOf _dataGettingClass = new ClassINeedOneInstanceOf();

in the DataService class

The error {"Value cannot be null.\r\nParameter name: value"} came from:

bool testDataOnly = Boolean.Parse(ConfigurationSettings["TestDataOnly"]);


the configuration file (web.config or app.config) that is used by the test framework is missing the settings for "TestDataOnly".

Need Your Help

Apache with Passenger doesn't load Rails app

ruby-on-rails ruby linux apache passenger

I'm developing a Rails app and am trying to configure the web server it's deployed on.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.