I do understand that mocks are useful to imitate a certain behaviour of
compononts which are sort of resource-demanding. But, I don't get the value
of using jMock for testing Managers as it is used in the tutorial. Let me
pick a test method:


    public void testFindByLastName() {
        log.debug("testing findByLastName");

        List people = new ArrayList();
        String lastName = "Smith";

        // set expected behavior on dao
        dao.expects(once()).method("findByLastName")
                .with(eq(lastName))
                .will(returnValue(people));

        List result = manager.findByLastName(lastName);
        assertSame(people, result);
    }

As far as I understand it, I am telling the mock (for PersonManagerDao) that
if a method "findByLastName" is invoked with a parameter "lastName", then it
should return the empty ArrayList "people". In a second step the manager
just invokes this method and the mock returns "people" which is stored in
"result". Now, comparing "people" with "result" does not make much sense and
unsurprisngly both lists must be the same. It looks like the following
conversation:

ME: "If I ask you for your name then answer 'Arthur'. So what's your name?". 
Arthur: "My name is Arthur."
ME: "You're right."
 
I have the deep impression that I misunderstand something, but I am unable
to identify my knowledge gap. Can anyone help and explain jMock's use in the
tutorial?

I can imagine to use jMock in the following way: I have some method which is
doing some computation which depends on information being stored in a
database. Let's assume I want to calculate the length of someone's first
name. Then with jMock I can simulate the database's behaviour. But, instead
of testing the retrieval function, I want to test the computation. Any idea
what the test would look like?  

Cheers,
Martin

-- 
View this message in context: 
http://www.nabble.com/jMock-in-Tutorial-not-self-explaining-tf4481302s2369.html#a12778467
Sent from the AppFuse - User mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to