English 中文(简体)
Can some one please provide the practical examples of stubs and drivers?
原标题:

I need some practical examples of stubs and drivers with respect to top-down and bottom-up approaches to testing. I don t require code here. Just the scenario based examples.

问题回答

A driver is a set of tests that test the interface of your class (methods, properties, constructor, etc).

A stub is a fake object that acts as a stand-in for other functionality like a database or a logger.

A mock is a fake object that has asserts in it.

Following is an example of a test using a mock object. If you take out the asserts, it becomes a stub. Collectively, these kinds of tests are drivers, because they exercise the methods and properties of your object.

Here is the example:

[Test]
public void TestGetSinglePersonWithValidId()
{
    // Tell that mock object when the "GetPerson" method is called to 
    // return a predefined Person
    personRepositoryMock.ExpectAndReturn("GetPersonById", onePerson, "1");
    PersonService service = new PersonService(
        (IPersonRepository) personRepositoryMock.MockInstance);
    Person p = service.GetPerson("1");
    Assert.IsNotNull(p);
    Assert.AreEqual(p.Id, "1");
}

http://www.zorched.net/2007/03/10/mocking-net-objects-with-nunit/





相关问题
Selenium not working with Firefox 3.x on linux

I am using selenium-server , selenium rc for UI testing in my application . My dev box is Windows with FireFox 3.5 and every thing is running fine and cool. But when i try to run selenium tests on my ...

Best browser for testing under Safari Mobile on Linux?

I have an iPhone web app I m producing on a Linux machine. What s the best browser I can use to most closely mimic the feature-limited version of Safari present on the iPhone? (It s a "slimmed down" ...

Code Coverage Tools & Visual Studio 2008 Pro

Just wondering what people are using for code coverage tools when using MS Visual Studio 2008 Pro. We are using the built-in MS test project and unit testing tool (the one that come pre-installed ...

Is there any error checking web app cralwers out there?

Wondering if there was some sort of crawler we could use to test and re-test everything when changes are made to the web app so we know some new change didn t error out any existing pages. Or maybe a ...

热门标签