kenegozi.com

<form id='kenegozi' action='post'></form>

   
2008 Feb 5

How would you test that?

Given the following code:

public void UpdatePerson(int id, string name)
{
    Person p = peopleRepository.Get(id);
    p.name = name;
    peopleRepository.Update(p);
}

 

One answer would be (using a pseudo mocking framework):

Person p = new Person();
Expect.Call(peopleRepository.Get(0))
        .Returns(p);
Expect.Call(peopleRepository.Update(p)); 
... 
service.UpdatePerson(0, "MyName");

 

Other approach would be (using pseudo coding again):

 

Person p = CreateAndInsertToDB();
service.UpdatePerson(p.id, "New Name");
 
FlushAndRecreateTheSession();
 
Person updated  = GetFromDB(p.Id);
Assert.Equal("New Name", updated.Name);

What would you do, and why?

 

(I'm tagging that also under altnetuk as it has been inspired by a session around test-granularity, mocking frameworks, etc.)

2007 Dec 20

Unit Testing 101 Article

tagged as: Testing

Usually I won't just link to another's post, but this one is a very good introductory level Unit Testing 101 Article, covering basics of the idea, and basic of nUnit and Rhino.Mocks.

 

A must read for Unit Testing newbies.

Subscribe

Statistics

283
440

Related Books

Related Jobs

Related Ads

search page | Blog's home | About me