http://www.jmock.org/
http://opensourcetips.blogspot.com/2007/11/jmock-tests.html
package com.test.jmock; interface Subscriber { void receive(String message); } package com.test.jmock; import java.util.ArrayList; import java.util.List; import junit.framework.*; class Publisher { List<Subscriber> list = new ArrayList<Subscriber>(); void add(Subscriber subscriber) { list.add(subscriber); } void publish(String message) { Subscriber s = list.get(0); s.receive(message); } } package com.test.jmock; import org.jmock.Mockery; import org.jmock.Expectations; import org.junit.*; public class PublisherTest { Mockery context = new Mockery(); @Test public void testOneSubscriberReceivesAMessage() { // set up final Subscriber subscriber = context.mock(Subscriber.class); Publisher publisher = new Publisher(); publisher.add(subscriber); final String message = "message"; // expectations context.checking(new Expectations() {{ one (subscriber).receive(message); }}); // execute publisher.publish(message); // verify context.assertIsSatisfied(); } }
easymock 보다 좀더 네이밍이나 코딩이 명확하고 편한 편인 것 같다.
개인적으로는 mockito 보다는 jmock 에 한표,
반응형
'emotional developer > detect-Java' 카테고리의 다른 글
TestNG (0) | 2010.07.16 |
---|---|
eclipse snippet (0) | 2009.06.27 |
Sun Java SystemApplication Server 9.1 PerformanceTuning Guide (0) | 2009.02.05 |