mocking

Mockito Passes but Code Coverage still low

package com.fitaxis.test; import java.sql.SQLException; import org.junit.Assert; import org.junit.Test; import org.mockito.Mockito; import org.mockito.invocation.InvocationOnMock; import org.mockito.stubbing.Answer; import static org.mockito.Mockito.*; import com.fitaxis.leaderboard.LeaderBoard; public class LeaderBoardTests { @T...

C# - Unit test, Mock?

The builtin unit test generator(VS) for the target classes should that be used or should I learn myself how to write a unit test? And whats this "Mock" thing? I hear it over and over but none cares to give a god damn explanation.. Thanks in advance. ...

How to mock a function with the signature `object ()`

I want to mock a method with the declaration A::B X(void). The definition is something as follows. class A { class B; virtual B X() = 0; }; class A::B { public: auto_ptr<int> something; }; My mock class, following this, is quite standard. class mA : public A { public: MOCK_METHOD0(X, A::B()); }; Compiled, howev...

When and when not to stub/mock a test

I am making a concerted effort to wrap my head around Rspec in order to move towards more of a TDD/BDD development pattern. However, I'm a long way off and struggling with some of the fundamentals: Like, when exactly should I be using mocks/stubs and when shouldn't I? Take for example this scenario: I have a Site model that has_many :b...

Unity Nunit & Rhino Mocks

Hi, could anyone give me a good example of using rhino mocks, nunit, and unity together. I am reading the help on each but there doesnt seem to be any good sample projects of how you would use them together and the way to set up projects /test projects using them. I.e. do you create new ioc containers in your test project which point t...

WSDL.exe - generate interface as well as concrete class for easy fake/mocks later.

Is it possible to get WSDL.exe to generate interfaces as well as, or instead of, concrete classes when it generates proxys to a web service? We're consuming a 3rd party webservice from an ASP.Net application, and have generated our proxy classes using WSDL.exe all well and good. I now want to write tests against my wrapper and business...

Should I use mocking for the following example

Hello, I am relatively new to using TDD and have been reading about mocking objects lately. I have the following test to test a method that given a date returns the next saturday. [TestMethod()] public void NextSaturdayTest() { DateTime date = new DateTime(); date = DateTime.Parse("2010-08-14"...

groovy / grails / unit testing / createCriteria.get

I can mock calls to: MyDomainClass.createCriteria().list{ eq('id',id) eq('anotherParameter',anotherParameterId) } with: def myCriteria = [ list : {Closure cls -> returnThisObject} ] MyDomainClass.metaClass.static.createCriteria = { myCriteria } as advised at: http://davistechyinfo.blogspot.com/2010/01/mocking-hibernat...

Mocking the initialize method on a ruby class?

How can I mock the initialize method on a ruby class? I'm doing some testing and want to mock out the object that is created from a new call. I tried to write a few things and none of them seemed to get the mock class to return from the new call. It just keeps returning the normal, expected object. EDIT: one attempt - class MockR...

Is it possible to mock the sqlite3 Cursor in Android when no db or table exists?

I am using a ContentProvider for caching results from a web-service query. It is an HTTP request and the response content is XML. Most of the data is cached, so I simply query the DB, if not found, request from webservice, insert in DB and requery the DB. Thus the response is always a Cursor from SQLiteDatabaseHelper. I have one resu...

Verify the number of times a protected method is called using Moq

In my unit-tests I'm mocking a protected method using Moq, and would like to assert that it is called a certain number of times. This question describes something similar for an earlier version of Moq: //expect that ChildMethod1() will be called once. (it's protected) testBaseMock.Protected().Expect("ChildMethod1") .AtMostOnce() .Ve...

How to turn off recording for an EasyMock object?

I am testing a servlet's doPost() method using EasyMock objects for the HttpServletRequest and HttpServletResponse arguments. Within the doPost() method I'm testing the request and response objects are used as arguments to a static method class for another class, and I want to disregard (i.e. not record as expected) any calls made on th...

How to test the order of mocked calls using EasyMock

Hi, It's easy enough in EasyMock to do: EasyMock.expect(service.methodCall()); but I noticed that this does not test the order in which I execute the calls, which in a case that I am trying to test is very important. Is there anyway to do this with EasyMock? ...

Comparing byte[] in LINQ-to-SQL and in a unit test that uses mocking

I have the following method: User IDataContext.AuthenticateUser(string userName, string password) { byte[] hash = PasswordHasher.HashPassword(userName, password); var query = from e in mContext.GetTable<User>() where e.Email == userName && e.Password == hash select e; return query.FirstOrDefault(); } Wh...

Mocking on the GAE development server ?

Hello, I'm trying to mock an HTTPServletRequest data on my development GAE server. I'm running Eclipse Plugin 1.3.7 I've tried to do this: package com.FOO.madservice.servlet.mock; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import static org.mockito.Mockito.*; @SuppressWarnings("seri...

How to test lambda functions with Moq?

There is a function: public class MyCacheClass : ICache { public void T GetObject<T>(Func<T> func) { T t; ... t = func(); ... return t; } } public class MyWorkClass : IWork { public Object MyWorkMethod(string value) { return new object(); } } These functions are ...

Grails - How to Unit Test addTo*

Is it possible to unit test addTo* functions in Grails ? thanks for your help. ...

Use DataTemplate in WPF with a mocked object.

I have following xaml code: <Window x:Class="MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" DataContext="{Binding MainWindow, Source={StaticResource Locator}}"> <Window.Resources> <DataTemplate DataType="{x:Type vm:...

throw checked Exceptions from mocks with Mockito

I'm trying to have one of my mocked objects throw a checked Exception when a particular method is called. I'm trying the following. @Test(expectedExceptions = SomeException.class) public void throwCheckedException() { List<String> list = mock(List.class); when(list.get(0)).thenThrow(new SomeException()); String test = list.g...

Mock object creation inside a method

If I have the following method: public void handleUser(String user) { User user = new User("Bob"); Phone phone = userDao.getPhone(user); //something else } When I'm testing this with mocks using EasyMock, is there anyway I could test the User parameter I passing into my UserDao mock like this: User user = new User("Bob")...