jmock

Comprehensive Pros/Cons of Mocking Frameworks for GWT

老子叫甜甜 提交于 2019-12-03 20:16:13
问题 I'm interested in using the right mocking framework for my GWT app. It's my understanding that Mockito, EasyMock, and jMock are some of the most popular for Java. Could someone list pros/cons for the mocking framework that they are most familiar with as it relates to GWT to help fellow GWT testing noobs like myself? Thanks in advance. 回答1: For the server side testing (RPC services) you can use any mocking framework you wish. spring-test library might be useful for mocking HttpRequest,

How to get started with testing(jMock)

≯℡__Kan透↙ 提交于 2019-12-03 13:47:07
I'm trying to learn how to write tests. I'm also learning Java, I was told I should learn/use/practice jMock, I've found some articles online that help to certain extend like : http://www.theserverside.com/news/1365050/Using-JMock-in-Test-Driven-Development http://jeantessier.com/SoftwareEngineering/Mocking.html#jMock And most articles I found was about test driven development, write tests first then write code to make the test pass. I'm not looking for that at the moment, I'm trying to write tests for already existing code with jMock. The official documentation is vague to say the least and

Unit test helper methods?

一曲冷凌霜 提交于 2019-12-03 11:35:40
问题 I have classes which previously had massive methods so I subdivided the work of this method into 'helper' methods. These helper methods are declared private to enforce encapsulation - however I want to unit test the big public methods. Is it good to unit test the helper methods too as if one of them fail the public method that calls it will also fail, and this way we can identify why it failed? Also in order to test these using a mock object I would need to change their visibility from

Unit test helper methods?

孤街醉人 提交于 2019-12-02 22:57:58
I have classes which previously had massive methods so I subdivided the work of this method into 'helper' methods. These helper methods are declared private to enforce encapsulation - however I want to unit test the big public methods. Is it good to unit test the helper methods too as if one of them fail the public method that calls it will also fail, and this way we can identify why it failed? Also in order to test these using a mock object I would need to change their visibility from private to protected, is this desirable? One way is to omit private and put the tests in the same package.

JMock Allow Other Method Calls

*爱你&永不变心* 提交于 2019-12-01 18:20:27
I'm using JMock to test the behavior of a class using an object. I want to test that the method a() is called. However, b() and c() also are called on the object too. Therefore if my expectations expect a() , it must also expect b() and c() to make the test pass. Is there a way to test only for a certain method, and allow anything else? Michael Barker Expect a() allow only methods b() & c() mockery.checking(new Expectations() {{ one(mockObject).a(); allowing(mockObject).b(); allowing(mockObject).c(); }}); Expect a() allow all other methods. mockery.checking(new Expectations() {{ one(mockObject

JMock Allow Other Method Calls

一曲冷凌霜 提交于 2019-12-01 17:44:59
问题 I'm using JMock to test the behavior of a class using an object. I want to test that the method a() is called. However, b() and c() also are called on the object too. Therefore if my expectations expect a() , it must also expect b() and c() to make the test pass. Is there a way to test only for a certain method, and allow anything else? 回答1: Expect a() allow only methods b() & c() mockery.checking(new Expectations() {{ one(mockObject).a(); allowing(mockObject).b(); allowing(mockObject).c(); }

About with(any(Class.class))) with JMock

廉价感情. 提交于 2019-12-01 02:52:57
With JMock: context.checking(new Expectations() {{ // Other oneOf() will() statements ... oneOf(shopAccount).enter(100, with(any(String.class))); will(returnValue(true)); // Other oneOf() will() statements ... }}); The following exception will be raised during execution: java.lang.IllegalArgumentException: not all parameters were given explicit matchers: either all parameters must be specified by matchers or all must be specified by values, you cannot mix matchers and values. Why i cannot do this way? using with(any(Klass.class)) ? Steve Freeman if you use a with clause for any parameter, you

About with(any(Class.class))) with JMock

元气小坏坏 提交于 2019-11-30 21:51:43
问题 With JMock: context.checking(new Expectations() {{ // Other oneOf() will() statements ... oneOf(shopAccount).enter(100, with(any(String.class))); will(returnValue(true)); // Other oneOf() will() statements ... }}); The following exception will be raised during execution: java.lang.IllegalArgumentException: not all parameters were given explicit matchers: either all parameters must be specified by matchers or all must be specified by values, you cannot mix matchers and values. Why i cannot do

How to Mock Command Object that is inside Controller

这一生的挚爱 提交于 2019-11-30 19:17:33
问题 I have a controller class, inside of which i have a command object. I have a method find() which uses this command object as follows: class itemController{ //command object class SearchCommand{ String email static constraints={ email blank:false,email:true } def find = {SearchCommand sc -> if(!sc.hasErrors()){ ----- do something--- } } Now, I am writing a test case to test the find method in the controller. But the test case fails at if(!sc.hasErrors()) as sc is still 'null'. I am not sure

Does Spring @DirtiesContext reload Spring context?

梦想与她 提交于 2019-11-29 18:33:37
问题 I have a test class that looks like @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(locations = {"classpath:/test-context.xml"}) @DirtiesContext(classMode = ClassMode.AFTER_EACH_TEST_METHOD) public abstract class TestClass { @Rule @Resource public JUnitRuleMockery jMockContext; public void test1() { //Expectations and test } public void test2() { //Expectations and test } } and in test-context.xml I define the JUnitRuleMockery plus several mock objects through a factory-method ,