MS Test, console application
hi,
i hoping answer qeustion me. bascially have simple console application. created unit tests it. last thing dsid right click on program class , create unit tests.
for class (the main entry point) unsure how test methods. there 2 "main" , merthod printing data console.
my question should testing class (both methods return void - both print console screen)? if have links show example of program class being unit tested or small examples.
thanks.
generally don't test main method because purpose should have instantiating things need run.
what can test application expected output result when prints console, start application , redirect console output (http://stackoverflow.com/questions/415620/redirect-console-output-to-textbox-in-separate-program-c-sharp):
void runwithredirect(string cmdpath) { var proc = new process(); proc.startinfo.filename = cmdpath; // set output redirection proc.startinfo.redirectstandardoutput = true; proc.startinfo.redirectstandarderror = true; proc.enableraisingevents = true; proc.startinfo.createnowindow = true; // see below output handler proc.errordatareceived += proc_datareceived; proc.outputdatareceived += proc_datareceived; proc.start(); proc.beginerrorreadline(); proc.beginoutputreadline(); proc.waitforexit(); } void proc_datareceived(object sender, datareceivedeventargs e) { // output in string e.data }
isn't ideal though , advice against in long term. want maybe change structure of application can in fact test portions of code seperately without being dependent on other parts.
i've written 2 blog posts might interest regarding this:
- http://blog.filipekberg.se/2011/12/20/adapting-to-inversion-of-control-and-dependency-injection/
- http://blog.filipekberg.se/2010/04/23/use-test-driven-development-to-verify-that-the-code-will-always-work/
so answer "should testing class (both methods return void - both print console screen)"; no, don't this, not work out in long term.
hope helps
mark replies helpful , correct ones answers! - http://blog.filipekberg.se
Visual Studio Languages , .NET Framework > Visual C#
Comments
Post a Comment