easymock

EasyMock vs Mockito: design vs maintainability? [closed]

余生颓废 提交于 2019-12-17 21:43:54
问题 Closed . This question is opinion-based. It is not currently accepting answers. Want to improve this question? Update the question so it can be answered with facts and citations by editing this post. Closed 2 years ago . One way of thinking about this is: if we care about the design of the code then EasyMock is the better choice as it gives feedback to you by its concept of expectations. If we care about the maintainability of tests (easier to read, write and having less brittle tests which

EasyMock: Void Methods

倖福魔咒の 提交于 2019-12-17 15:26:31
问题 I have a method that returns void in a class that is a dependency of the class I want to test. This class is huge and I'm only using this single method from it. I need to replace the implementation of this method for the test as I want it to do something different and I need to be able to access the parameters this method receives. I cannot find a way of doing this in EasyMock. I think I know how to do it with Mockito by using doAnswer but I don't want to add another library unless absolutely

PowerMock ECLEmma coverage issue

女生的网名这么多〃 提交于 2019-12-17 06:47:19
问题 We are using EasyMock and PowerMock with JUnit. The coverage tool used is ECLEmma. With EasyMock, it shows the coverage properly in green (as covered). However, for the code that is unit tested with PowerMock, the coverage is shown in red (uncovered). Have read similar questions on the web. However, just wanted to check if there is a solution for this. Thanks Venkatesh 回答1: It's a known problem : https://github.com/jayway/powermock/issues/422 And it has been for a long time, it won't be fixed

EasyMock and modifing a mutable method parameter

南楼画角 提交于 2019-12-13 13:06:50
问题 How does one use EasyMock to modify a mocked method's mutable method parameter? For example, I have class that uses a BlockingQueue. I want to mock the BlockingQueue member for unit testing. My class calls the method queue.drainTo(Collection c). Calling this method removes elements from the queue and adds them to the collection. How would I mock this behavior using EasyMock? Examples would be great. 回答1: You can use andAnswer and getCurrentArguments: public void testDrainToQueue() {

How to make the non-mocked function run in normal behavior?

狂风中的少年 提交于 2019-12-13 05:53:37
问题 I am new in EasyMock, i have a scenario like this: I create a mock for FolderUtils.ABC(). However, inside the FolderUtils.class, there are many methods that I will use with the ABC() when i run this unitTest. I only want the ABC() return the mock values, otherwise they will run as their normal behavior. How can I do that? FolderUtils contantsUnderTest = EasyMock.createMock(FolderUtils.class); EasyMock.expect(contantsUnderTest.ABC(EasyMock.notNull(UserKey.class))).andReturn("123").anyTimes();

PowerMock fails with JerseyTest

拜拜、爱过 提交于 2019-12-13 02:25:34
问题 We're writing unit tests for a Jersey Java REST service using PowerMock. We have to use PowerMock because we use numerous static methods in a legacy system. We're using PowerMock with EasyMock. Whenever we try to inherit from JerseyTest, the whole framework fails. It's a gradle based project, and the pertinent build.gradle lines are below. testCompile 'junit:junit:4.12' testCompile group: 'org.easymock', name: 'easymock', version: '3.5.1' testCompile group: 'org.easymock', name:

Easymock createMock vs @Mock

烈酒焚心 提交于 2019-12-13 01:54:04
问题 I'm using Easymock with junit for writing my unit tests. I have seen different tests following different methods to create mock objects. Is there any difference between Easymock.createMock() and @Mock annotation ? Obj obj = EasyMock.createMock(Obj.class); and @Mock private Obj obj; Is there any difference between the two ? 回答1: The annotated way of creating the mock is only available since EasyMock 3.2. With the @Mock annotation the mock is injected, otherwise it's created by you. From a

How to test methods that deal with SQLite database in android?

时光怂恿深爱的人放手 提交于 2019-12-12 20:35:29
问题 I have made an application that deals with SQLite database by opening, retrieving data from, and inserting data to it. Now I want to test my methods. So , I have two classes, one " SQLiteHelper " which extends SQLiteOpenHelper to open,create,and upgrade the database, and the other is a DataSource class, that makes an SQLiteDatabase object,and contains all my methods that deals with the database. So for calling any method I need to call the open method in the SQLiteHelper class, catch the

EasyMock expecting private method calls

强颜欢笑 提交于 2019-12-12 14:49:06
问题 Lets say I have a method that looks like this: public static String[] parseFoo(Foo anObject){ Foo anotherObject = parseFoo2(anObject); ... } private static Foo parseFoo2(Foo anObject){ ... } and both methods are in the same class. parseFoo2 is just a helper method that helps parseFoo get some stuff done. I'm trying to test the method parseFoo. Is there anyone in EasyMock that I can specify a return value on that private method call for parseFoo2 like the way I can specify instance method

How to mock behavior of generic method with wildcard

核能气质少年 提交于 2019-12-12 12:44:46
问题 I'm using EasyMock (3.2). I want to write a test for part of my security system based on Spring Security. I want to mock the Authentication so that it returns empty list of authorities. Its method declaration is as follows: Collection<? extends GrantedAuthority> getAuthorities(); So I write a test: Authentication authentication = createMock(Authentication.class); Collection<? extends GrantedAuthority> authorities = Collections.emptyList(); expect(authentication.getAuthorities()).andReturn