easymock

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,

Testing code which calls native methods

冷暖自知 提交于 2019-12-03 12:10:52
I have a class like this: public final class Foo { public native int getBar(); public String toString() { return "Bar: " + getBar(); } } Please note that getBar() is implemented with JNI and that the class is final . I want to write a junit test to test the toString() method. For this I need to mock the getBar() method and then run the original toString() method to check the output. My first thought was that this must be impossible but then I found PowerMock which supports testing final classes and native methods according to the feature list. But so far I had no success with it. The best

How to mock the HttpServletRequest? [duplicate]

自作多情 提交于 2019-12-03 10:26:31
This question already has an answer here: Creating a mock HttpServletRequest out of a url string? 4 answers I have a function that looks for a query parameter and returns a boolean: public static Boolean getBooleanFromRequest(HttpServletRequest request, String key) { Boolean keyValue = false; if(request.getParameter(key) != null) { String value = request.getParameter(key); if(keyValue == null) { keyValue = false; } else { if(value.equalsIgnoreCase("true") || value.equalsIgnoreCase("1")) { keyValue = true; } } } return keyValue; } I have both junit and easymock in my pom.xml, how do I go about

java.lang.IllegalStateException: missing behavior definition for the preceding method call getMessage(“title”)

*爱你&永不变心* 提交于 2019-12-03 09:35:06
I'm using EasyMock(version 2.4) and TestNG for writing UnitTest. I have a following scenario and I cannot change the way class hierarchy is defined. I'm testing ClassB which is extending ClassA. ClassB look like this public class ClassB extends ClassA { public ClassB() { super("title"); } @Override public String getDisplayName() { return ClientMessages.getMessages("ClassB.title"); } } ClassA code public abstract class ClassA { private String title; public ClassA(String title) { this.title = ClientMessages.getMessages(title); } public String getDisplayName() { return this.title; } }

How can I mock a method in easymock that shall return one of its parameters?

≡放荡痞女 提交于 2019-12-03 05:35:41
问题 public Object doSomething(Object o); which I want to mock. It should just return its parameter. I tried: Capture<Object> copyCaptcher = new Capture<Object>(); expect(mock.doSomething(capture(copyCaptcher))) .andReturn(copyCatcher.getValue()); but without success, I get just an AssertionError as java.lang.AssertionError: Nothing captured yet . Any ideas? 回答1: I was looking for the same behavior, and finally wrote the following : import org.easymock.EasyMock; import org.easymock.IAnswer; /** *

EasyMock : java.lang.IllegalStateException: 1 matchers expected, 2 recorded

匿名 (未验证) 提交于 2019-12-03 01:38:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I am having a problem with EasyMock 2.5.2 and JUnit 4.8.2 (running through Eclipse). I have read all the similar posts here but have not found an answer. I have a class containing two tests which test the same method. I am using matchers. Each test passes when run alone. The first test always passes - this is true if I switch the order of the tests in the file. Here is a simplified version of the test code: private Xthing mockXthing; private MainThing mainThing; @Before public void setUp() { mockXthing = EasyMock.createMock(Xthing.class);

EasyMock andReturn() vs andStubReturn()

匿名 (未验证) 提交于 2019-12-03 01:25:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: What is the difference between using andReturn(T value) vs andStubReturn(T value) for EasyMock? In what situation would you use andStubReturn() where andReturn() can't achieve the same result? 回答1: You use a stub return for a method call on the mock that you expect to happen but aren't otherwise interested in. You use a regular return for a "regular" method call. Consider the following method: public void someMethod(String arg) { if (logger.isDebugEnabled()) { logger.debug("Calling doSomething() on service " + service.getName().hashCode());

EasyMock 3.0, mocking class throws java.lang.IllegalStateException: no last call on a mock available

匿名 (未验证) 提交于 2019-12-03 01:23:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: Running the following unit test throws the exception: java.lang.IllegalStateException: no last call on a mock available import org.easymock.*; import org.junit.*; public class MyTest { @Test public void testWithClass() { Thread threadMock = EasyMock.createMock(Thread.class); EasyMock.expect(threadMock.isAlive()).andReturn(true); } } I am not sure what I am doing wrong and can not find any good examples on the web. How do you mock a class using EasyMock 3.0. What is wrong with the above unit test? Any help would be greatly appreciated. My

EasyMock: How do I create a mock of a genericized class without a warning?

那年仲夏 提交于 2019-12-03 00:56:30
The code private SomeClass<Integer> someClass; someClass = EasyMock.createMock(SomeClass.class); gives me a warning "Type safety: The expression of type SomeClass needs unchecked conversion to conform to SomeClass<Integer>". Barend AFAIK, you can't avoid the unchecked warning when a class name literal is involved, and the SuppressWarnings annotation is the only way to handle this. Note that it is good form to narrow the scope of the SuppressWarnings annotation as much as possible. You can apply this annotation to a single local variable assignment: public void testSomething() {

EasyMock的本地部署

匿名 (未验证) 提交于 2019-12-03 00:09:02
随着前后端分离模式的盛行,我们的前后端在开发的过程中是无法进行数据的传输的。为了开发能够正常进行,我们需要模拟一些假数据供前端开发使用。Easy Mock作为一个可视化的服务,不仅能够快速生成模拟数据,而且很容易操作,学习成本相对较低。我们在创建项目的时候,其实是可以直接在 Easy Mock 的官网 登录账号之后,进行我们项目所需要的数据模拟操作。随着使用人数的增多,官网提供的服务体验感越来越差,浪费时间影响开发进度。基于此,我们需要在本地部署一套自己的EasyMock服务。 一、安装前的准备 根据Easy Mock的 GitHub说明文档 ,我们在安装Easy Mock服务之前,需要安装Node.js(v8.x, 不支持 v10.x)& MongoDB(>= v3.4)& Redis(>= v4.0)。接下来,我们一一介绍这些软件的安装步骤。 Node.js的安装 下载软件 进入到Node.js的 软件仓库 中,选择对应的版本,比如8.8.1,复制对应的版本链接 node-v8.8.1-linux-x86.tar.gz ,下载到本地。 wget https://nodejs.org/dist/v8.8.1/node-v8.8.1-linux-x86.tar.gz 解压软件 tar -zxf node-v8.8.1-linux-x86.tar.gz 设置软件的全局变量