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


i have public static class i'm trying unit test using visual studio 2012's built in testing framework. when try run unit tests on error:

the type initializer 'foo.bar.controllers.dataservice' threw exception.  

the inner exception says:

 {"value cannot null.\r\nparameter name: value"}   @ system.boolean.parse(string value) 

the class i'm trying 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 , stuff) {                 infolist = _datagettingclass.getinfofromawesomeotherservice(svcname);             }             return infolist         }          // other methods 1 above return data other things , in different ways         // public static, return data, , use method _dependecygettingclass     } } 

my understanding of static classes static fields first time class called field instantiates , can used on. backed code working, ex: website uses data , such

is unit test framework doing weird , not calling class in same way "typical" c# code does? if so, there way can change mstest code?

also, use pattern code architecture , design correct? should class (with reliance on 1 instance of _datagettingclass) written differently?

thanks!

edit: unit test class calls method is:

namespace foo.test {     [testclass]     public class dataservicetests     {          [testmethod]         public void getinfolistusingservicename()         {             string servicename = "service001";             var result = dataservice.getserviceinfolist(servicename);             assert.isnotnull(result);         }      } } 

and line reference parse inner exception is:

private static classineedoneinstanceof _datagettingclass = new classineedoneinstanceof(); 

in dataservice class

the error {"value cannot null.\r\nparameter name: value"} came from:

bool testdataonly = boolean.parse(configurationsettings["testdataonly"]); 

the configuration file (web.config or app.config) used test framework missing settings "testdataonly".


Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -