When creating methods, should every object instantiated inside that method be passed in as a parameter so that those objects can be mocked in our unit tests?
We have a lot of methods here at work that have no associated unit tests and upon writing tests retrospectively; we find that there are quite a lot of objects instantiated inside t...
I have a Singleton that is accessed in my class via a static property like this:OtherClassNotBeingTested.Instance.SomeInstanceMethod()
I would like to test my class with out making one of these objects. Is there a way for RhinoMocks to return a stub when the getter for the static property Instance is called?
To be clearer, here is the...
How would you check the parameters on a function that accepts a Dictionary?
IDictionary<string, string> someDictionary = new Dictionary<string, string> {
{"Key1", "Value1"},
{"Key2", "Value2"}
};
Expect.Call(delegate {someService.GetCodes(someDictionary);}).Constraints(...);
Basically, I want to verify that the parameter for GetC...
Hi all:
I'm currently trying to mock the following method using Jack. The code example is as below:
var ID = "id";
$('#' + ID + ' > div > table').each(function) {
var nodeSpan = $(this).find('span.' + NODE_INDICATORS)[0];
.
.
.
});
How should I approach it? Are there jQuery/QUnit functions that allows me to create a DOM node/el...
Hi,
I have always been faking/mocking/stubbing HttpContext somehow in ASP.NET (much easier in ASP.NET MVC/MonoRail).
But I can see that HttpContext itself can be constructed easily, literally with couple of lines of code.
var tw = new StringWriter();
var workerReq = new SimpleWorkerRequest("/webapp", @"c:\here\there\wwwroot", "pag...
I need to mock a GrailsControllerClass interface. Instance should have a static variable defined. The problem is that MockFor and StubFor don’t give you an option for adding static members.
So, I write my abstract class that extends GrailsControllerClass
abstract class MyController implements GrailsControllerClass {
static myDefiniti...
I have a piece of logic I want to test and it uses dependency injected interface with one (or more) void methods, example:
interface IMyService
{
void MethodA (MyComplexObject arg1, int arg2);
}
What I would want is to create a stub for this IMyService that would just record the method invocations of MethodA and I would later be a...
Okay so I have been trying to get into IoC lately. However, I keep running into one hurdle - that is the fact that I love using mock objects.
They are quick and painless to setup.
However, if I use IoC all over the place in my code then it forces me to create test implementations (and configurations) of my objects instead of using moc...
I've got code that only needs to run on a certain version of ActiveRecord (a workaround for a bug on old AR libraries). This code tests the values of ActiveRecord::VERSION constants to see if it needs to be run.
Is there a way to mock out those constants in rspec so I can test that code path without relying on having the right ActiveRec...
I'm trying to use qMock to test some javascript code, and am having problems in IE. The tests are passing in chrome and firefox, but in IE I'm getting "Object doesn't support this property or method" for every test that uses the mocked object. It's almost like IE doesn't see that there is a mock implementation of the function. Has any...
I have worked with code which had NUnit test written. But, I have never worked with mocking frameworks. What are they? I understand dependency injection and how it helps to improve the testability. I mean all dependencies can be mocked while unit testing. But, then why do we need mocking frameworks? Can't we simply create mock objects an...
see also "What should I consider when
choosing a mocking framework for
.Net"
I'm trying to decide on a mocking framework to use on a .NET project I've recently embarked on. I'd like to speed my research on the different frameworks. I've recently read this blog post http://codevanced.net/post/Mocking-frameworks-comparison.aspx ...
Hi, I am currently developing an GUI to an embedded system. (I am using GUI to descripe my app opposed to interface to avoid confusion with the progamatic meaning)
Context
I have created a class which simulates the embedded system. I do all my communications through a Connection class I have designed which can communicate via TCP/Seria...
I am using RhinoMocks, I need to stub a method, and always have it return the third parameter, regardless of what is passed in:
_service.Stub(x => x.Method(parm1, parm2, parm3)).Return(parm3);
Obviously, it ain't that easy. I don't always know what the parms are going to be, but I know I always want to return the 3rd one.
...
I have a method that I want to test which expects an IEnumerable<T> as a parameter.
I'm currently mocking the contents of the IEnumerable<T> as follows (Using Moq):
var mockParent = new Mock<ICsvTreeGridExportable>();
var mockChild = new Mock<ICsvTreeGridExportable>();
How do it put these mocked objects inside an IEnumerable<T> so ...
I'm looking for some examples on how to do the following Mock Tests using StructureMap or Unity with NUnit.
I have the following code structure
public interface IDAL
{
List<Model> Method1(int id);
}
public class DAL : IDAL
{
public List<Model> Method1(int id)
{
List<Model> retval = new List<Model>();
DbComman...
Is there a good standalone mock framework for PHP? Currently I am using Simpletest framework for unit testing. I like the framework, but I dont like how you create and setup a mock in it. I then tried PHPMock, I like how it can be used, but it I encountered some bugs that get annoying over time ... Or would it be best to switch over to P...
Has anyone ever experienced a unit test that fails and when they tried to debug it to find out where the failure was occurring, the unit test succeeds when running the code in the debugger?
I'm using Eclipse 3.5.1 with EPIC 0.6.35 and ActiveState ActivePerl 5.10.0. I wrote module A and module B both with multiple routines. A routine...
I just started using mock objects (using Java's mockito) in my tests recently. Needless to say, they simplified the set-up part of the tests, and along with Dependency Injection, I would argue it made the code even more robust.
However, I have found myself tripping in testing against implementation rather than specification. I ended u...
I have an interesting situation where I am refactoring a bunch of ObjC iPhone code to create a C++ API. I'm a novice to C++ and looking into C++ mocking frameworks to augment the work I'd done using OCUnit and poor man's mocks. I ran across googlemock and wanted to know if anyone has ever used it for iPhone development? Also, how can I s...