Re: Unit Testing Model-View-Presenter
- From: "Sean Chambers" <dkode8@xxxxxxxxx>
- Date: 5 Oct 2006 19:36:35 -0700
Therein lies the problem, I can't seem to figure out how to properly
attach to the presenters from my unittest code, and then call InitView
without my production presenters actually connecting to the DB and
retirieving data.
Have you got a high level example?
Could be I am not exactly understanding the approach...
SN
Let's say I have a Presenter that presents a username from the
database.
within the InitView method, I would be attaching the view to the model
like so:
public void InitView() {
ISession session = NHibernate.Session() // just for the example
this.view = session.Get(typeof(User), id); // User is the class
that attaches to the view
}
Now, this code is fine in the production enviorment, but in my unit
test, I don't want to be retrieving any data from the backend, I want
to mock the User object, but then how do I actually get the mock in
there, thats why I made the test method like so:
public void InitViewTest() {
User user = new User();
user.UserName = "sean";
this.view = user;
}
I guess what I'm looking for here, is what is the proper way to supply
my presenter with a mock object, so that I can effectively test MVP.
into the chain while unit testing.From all the books I've read, they always stress not to delve to far
I think I'm just missing something simple here, I am imagining that the
piece I'm missing is Dependency Injection, but I'm not sure
Thanks
Sean
.
- Follow-Ups:
- Re: Unit Testing Model-View-Presenter
- From: Joanna Carter [TeamB]
- Re: Unit Testing Model-View-Presenter
- From: Jon Skeet [C# MVP]
- Re: Unit Testing Model-View-Presenter
- References:
- Unit Testing Model-View-Presenter
- From: Sean Chambers
- Re: Unit Testing Model-View-Presenter
- From: Steven Nagy
- Unit Testing Model-View-Presenter
- Prev by Date: Re: AHH Spam and making a blocker?
- Next by Date: Re: Fastest way to work with DataTable
- Previous by thread: Re: Unit Testing Model-View-Presenter
- Next by thread: Re: Unit Testing Model-View-Presenter
- Index(es):