I confess up front that of all of the hundreds of skills I've had to learn over the years, at this point I'm still not up on unit testing. I haven't used the tools once, haven't read a book or done my homework on this one, and don't know AAA from the company that tows my car. In JustMock I think I see a tool that can help with common development. I just don't want to have to research another paradigm like unit testing (yet) in order to use what seems like a great tool. But all of the examples seem to be completely based on unit testing.
Here is an example of how I'd like to use JustMock. I have an ASP.NET app that makes synchronous WebRequests out to other sites to aggregate results. My code might look something like this:
The problem is that I in testing through Visual Studio I don't have the live web server environment, and I don't want to have to do a live call through LibraryX to get a IList<ClassA> that I need elsewhere in my code. It would be great if I could generate that list without having to write the manual code to generate N instances of ClassA. The issue is compounded when ClassA is sealed and instances are constructed internally in LibraryX, and I actually can't manually create those instances anyway without a lot of grief.
So can I do something like this?
As I see it, JustMock doesn't seem to have the tools it needs to create a mock list of ClassA objects ... or maybe that's exactly what JustMock is great at doing!? I really don't know because I'm not "getting" this from any of the documentation. Is there something else that does what I want here? Or is the universal solution still to just lump it and do it all manually?
Thanks!
Here is an example of how I'd like to use JustMock. I have an ASP.NET app that makes synchronous WebRequests out to other sites to aggregate results. My code might look something like this:
IList<ClassA> GetGridData(
string
info) {
IList<ClassA> list = LibraryX.DoSomething(info);
// web request done in here
if
(list.Count == 0)
list =
null
;
return
list;
}
The problem is that I in testing through Visual Studio I don't have the live web server environment, and I don't want to have to do a live call through LibraryX to get a IList<ClassA> that I need elsewhere in my code. It would be great if I could generate that list without having to write the manual code to generate N instances of ClassA. The issue is compounded when ClassA is sealed and instances are constructed internally in LibraryX, and I actually can't manually create those instances anyway without a lot of grief.
So can I do something like this?
IList<ClassA> GetGridData(
string
info) {
#if Testing
IList<ClassA> list = Mock.Create<IList<ClassA>>(info);
// or....
IList<ClassA> list = Mock.Create<LibraryX.ClassAFactory>().DoSomething(info);
#else
IList<ClassA> list = LibraryX.ClassAFactory.DoSomething(info);
// web request done in here
#endif
if
(list.Count == 0)
list =
null
;
return
list;
}
As I see it, JustMock doesn't seem to have the tools it needs to create a mock list of ClassA objects ... or maybe that's exactly what JustMock is great at doing!? I really don't know because I'm not "getting" this from any of the documentation. Is there something else that does what I want here? Or is the universal solution still to just lump it and do it all manually?
Thanks!