Steve Freeman | 1 Mar 2009 12:35
Picon

Re: Thoughts on jMock and multithreading?

I'm a bit undecided on this one. So far, we've had a very opinionated  
story, which is that JMock doesn't do multithreading. If you want to  
test threaded code, then there are other ways to do that, especially  
now that Hamcrest is shaping up.

One of our strong claims is that jmock will help you write the "right"  
kind of code because it pushes you into the appropriate corners, for  
example that threaded code should minimise its synchronisation points.  
I fear that we'll lose the message if we make it too easy -- that's  
why mocking classes is an extension and not built-in.

An alternative to implementing support for threads is to complain when  
they're found, which would solve the confusing failures problem.

S.

On 28 Feb 2009, at 17:13, Nat Pryce wrote:
> There's some debate going on among the jMock developers and the users
> they know about whether jMock should support testing multithreaded
> code.
>
> On one side, at the moment jMock forces you to separate the functional
> behaviour of a unit from larger scale concurrency policies, so that
> you can test the unit with the DeterministicExecutor or
> DeterministicScheduler.
>
> On the other side, lots of Java code is multithreaded and plenty of
> people use jMock in multithreaded tests and get wierd errors as a
> result.
>
(Continue reading)

Rodrigo Dantas | 2 Mar 2009 21:27
Picon

JMock return ClassCastException!

 Hi all,

    Sorry my English, but i written from Brazil and not haven a good field of
language!
    I written my first test case with JMock2. My method testing is following:

    context.checking(new Expectations() {{
      final Criteria criteria = context.mock(Criteria.class);
      oneOf(session).createCriteria(AlunoCurso.class); 			
      oneOf(criteria).add(Restrictions.eq("codigo",Integer.parseInt("403535")));			
      oneOf(criteria).uniqueResult();
      will(returnValue(new AlunoCurso()));
    }});
		
    AlunoCurso alunoCurso = alunoCursoBean.getAlunoCursoPorLogin("403535");
    assertNotNull(alunoCurso);
    Could someone help me? You are missing something in configuring jmock2?

     Thanks! 
     dantas.

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email

Steve Freeman | 2 Mar 2009 21:54
Picon

Re: JMock return ClassCastException!

1) can you show us something of the actual stack trace?
2) the context.mock() line should really be outside the checking  
clause, but I'm not sure if that's your problem.

S

On 2 Mar 2009, at 20:27, Rodrigo Dantas wrote:
> Hi all,
>
>    Sorry my English, but i written from Brazil and not haven a good  
> field of
> language!
>    I written my first test case with JMock2. My method testing is  
> following:
>
>    context.checking(new Expectations() {{
>      final Criteria criteria = context.mock(Criteria.class);
>      oneOf(session).createCriteria(AlunoCurso.class); 			
>       
> oneOf 
> (criteria 
> ).add(Restrictions.eq("codigo",Integer.parseInt("403535")));			
>      oneOf(criteria).uniqueResult();
>      will(returnValue(new AlunoCurso()));
>    }});
> 		
>    AlunoCurso alunoCurso =  
> alunoCursoBean.getAlunoCursoPorLogin("403535");
>    assertNotNull(alunoCurso);
>    Could someone help me? You are missing something in configuring  
(Continue reading)

Rodrigo Dantas | 2 Mar 2009 23:24
Picon

Re: JMock return ClassCastException!

Steve Freeman <steve <at> ...> writes:

> 
> 1) can you show us something of the actual stack trace?
> 2) the context.mock() line should really be outside the checking  
> clause, but I'm not sure if that's your problem.
> 
> S
> 
> On 2 Mar 2009, at 20:27, Rodrigo Dantas wrote:
> > Hi all,
> >
> >    Sorry my English, but i written from Brazil and not haven a good  
> > field of
> > language!
> >    I written my first test case with JMock2. My method testing is  
> > following:
> >
> >    context.checking(new Expectations() {{
> >      final Criteria criteria = context.mock(Criteria.class);
> >      oneOf(session).createCriteria(AlunoCurso.class); 			
> >       
> > oneOf 
> > (criteria 
> > ).add(Restrictions.eq("codigo",Integer.parseInt("403535")));			
> >      oneOf(criteria).uniqueResult();
> >      will(returnValue(new AlunoCurso()));
> >    }});
> > 		
> >    AlunoCurso alunoCurso =  
(Continue reading)

Nat Pryce | 2 Mar 2009 23:52
Picon

Re: Thoughts on jMock and multithreading?

2009/3/1 Steve Freeman <steve@...>:
> I'm a bit undecided on this one. So far, we've had a very opinionated story,
> which is that JMock doesn't do multithreading. If you want to test threaded
> code, then there are other ways to do that, especially now that Hamcrest is
> shaping up.
>
> One of our strong claims is that jmock will help you write the "right" kind
> of code because it pushes you into the appropriate corners, for example that
> threaded code should minimise its synchronisation points. I fear that we'll
> lose the message if we make it too easy -- that's why mocking classes is an
> extension and not built-in.
>
> An alternative to implementing support for threads is to complain when
> they're found, which would solve the confusing failures problem.

The default will be to complain if used from multiple threads, to
nudge design towards a clear separation of logic from concurrency
policy.

However, you still need to test multithreaded code:

1) Even when you separate logic and concurrency policy, you need to
stress-test synchronisation.  JMock can help here by isolating
synchronisation points to pinpoint failures.

2) When you implement an abstraction in terms of third-party code that
calls into your object from multiple threads you may need to use mocks
to test outgoing calls from your object.

--Nat
(Continue reading)

Steve Freeman | 3 Mar 2009 00:24
Picon

Re: Re: JMock return ClassCastException!

it looks like createCriteria() has to return the Mock Criteria.

S.

On 2 Mar 2009, at 22:24, Rodrigo Dantas wrote:
> Steve Freeman <steve <at> ...> writes:
>
>>
>> 1) can you show us something of the actual stack trace?
>> 2) the context.mock() line should really be outside the checking
>> clause, but I'm not sure if that's your problem.
>>
>> S
>>
>> On 2 Mar 2009, at 20:27, Rodrigo Dantas wrote:
>>> Hi all,
>>>
>>>   Sorry my English, but i written from Brazil and not haven a good
>>> field of
>>> language!
>>>   I written my first test case with JMock2. My method testing is
>>> following:
>>>
>>>   context.checking(new Expectations() {{
>>>     final Criteria criteria = context.mock(Criteria.class);
>>>     oneOf(session).createCriteria(AlunoCurso.class); 			
>>>
>>> oneOf
>>> (criteria
>>> ).add(Restrictions.eq("codigo",Integer.parseInt("403535")));			
(Continue reading)

Rodrigo Dantas | 3 Mar 2009 01:08
Picon

Re: JMock return ClassCastException!

 I tried to change as follows, but continue same error:

   context.checking(new Expectations() {{
	final Criteria criteria = context.mock(Criteria.class);
	oneOf(session).createCriteria(AlunoCurso.class); 			
	oneOf(criteria).add(Restrictions.eq("codigo", Integer.parseInt("403535")));			
	oneOf(criteria).uniqueResult(); 
	will(onConsecutiveCalls(
        	returnValue(criteria),
		returnValue(criteria),
		returnValue(new AlunoCurso())
	    ));
        }});

   whereas in the method getAlunoCursoPorLogin got the call cascade, which is
the correct way to create Expectations?

   Thanks for help me!!

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email

Steve Freeman | 3 Mar 2009 08:25
Picon

Re: Re: JMock return ClassCastException!

try

final AlunoCurso curso = new AlunoCurso();

allowing(session).createCriteria(AlunoCurso.class);
   will(returnValue(criteria);
allowing(criteria).add(....)
allowing(criteria).uniqueResult();
   will(returnValue(curso);

S.

On 3 Mar 2009, at 00:08, Rodrigo Dantas wrote:

> I tried to change as follows, but continue same error:
>
>   context.checking(new Expectations() {{
> 	final Criteria criteria = context.mock(Criteria.class);
> 	oneOf(session).createCriteria(AlunoCurso.class); 			
> 	oneOf(criteria).add(Restrictions.eq("codigo",  
> Integer.parseInt("403535")));			
> 	oneOf(criteria).uniqueResult();
> 	will(onConsecutiveCalls(
>        	returnValue(criteria),
> 		returnValue(criteria),
> 		returnValue(new AlunoCurso())
> 	    ));
>        }});
>
>   whereas in the method getAlunoCursoPorLogin got the call cascade,  
(Continue reading)

Rodrigo Dantas | 3 Mar 2009 14:16
Picon

Re: JMock return ClassCastException!


  Thanks Freeman, but not worked. My problem is that's my mock object generates
a other object, and this other object call a function what return the object
wished. I need mock this other object. I do  other test, and if work,
 i post here.

  att, 

   Dantas

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email

Rodrigo Dantas | 4 Mar 2009 22:32
Picon

Re: JMock return ClassCastException!

Rodrigo Dantas <rodrigodantas <at> ...> writes:

> 
> 
>   Thanks Freeman, but not worked. My problem is that's my mock object generates
> a other object, and this other object call a function what return the object
> wished. I need mock this other object. I do  other test, and if work,
>  i post here.
> 
>   att, 
> 
>    Dantas
> 
> ---------------------------------------------------------------------
> To unsubscribe from this list, please visit:
> 
>     http://xircles.codehaus.org/manage_email
> 
> 

	
Hi Mr. Freeman,

     After reading some articles, did some other tests that did not work. Then I
began to analyze my test case and noticed that what I really need is a way to
invoke a method of an object from the call of a method of my mock object.

     Abaixo segue o metodo que usa o objeto mock:

     public AlunoCurso getAlunoCursoPorLogin(String login) {
(Continue reading)


Gmane