Continuing another but similar question about testing (see here). I'll use a similare example (pseudocode)
class LinkDisplayer
method constructor(LinkStorage)
method displayLatestLinksByCategory(number_of_them)
class LinkStorage
method saveLink(Link)
method retrieveLatestLinksByCategory(category, number_of_them)
class ...
I have used the RhinoMocks product for quite some time and have been quite happy with the product - never had a reason to look elsewhere really. I was recently asked by the good folks at TypeMock to give their product a whirl and was wondering what other developers opinions are about Typemock Isolator. Are there any other isolation/moc...
Hi,
I often find myself changing my code to make it more testable, I always wonder whether this is a good idea or not. Some of the things I find myself doing are:
Adding setters just so I can set an internal object to a mock.
Adding getters for internal maps/lists so I can check the internal state of the object has changed after perf...
I'm having problems verifying Ienumerable / Array type parameters when setting up expectation for methods call on my mock objects. I think since it's matching different references it doesn't consider it a match. I just want it to match the contents of the array, sometimes I don't even care about the order.
mockDataWriter.Setup(m => m....
I've this confusion all the time. If I write a code which uses fake code to assert some operation, how do i trust my real implementation when it is started really using the real objects instead of fake ones.
For example, I've this code --
[Test]
public void CanCreateContactsWithData()
{
using(ISession session = fact...
I'm trying to mock a method that has the equivalent of the following signature:
- (NSDictionary *) uploadValues:(BOOL)doSomething error:(NSError **)error
I want it to return a small dictionary so that my test can make sure the code uses the dictionary properly. however, no matter what i do OCMock always returns nil from the method, r...
I'm writing a special sort of chat/forum software and need a source of mock conversations to use in screenshots, demos and tests.
They should contain no real names or other potentially harmful information, should be 100% correct English and should make at least some sense in relation to each other.
Example:
Message #1 Subject: Hell...
How do I test the following code with mocks (using mocks, the patch decorator and sentinels provided by Michael Foord's Mock framework):
def testme(filepath):
with open(filepath, 'r') as f:
return f.read()
...
Hello,
I think understand the definition of State / Interaction based testing (read the Fowler thing, etc). I found that I started state based but have been doing more interaction based and I'm getting a bit confused on how to test certain things.
I have a controller in MVC and an action calls a service to deny a package:
public Acti...
I'm testing an extension method on an interface 'ISomeInterface'. The extension method actually calls to another method in the interface.
How do I set up a mock and the appropriate expectations (i want to set the expectation that 'SomeMethod', which is an defined method in the interface with a different signature then this extension met...
A couple of days ago, I saw the CoClassAttribute being used in a way I haven't imagined before.
[ComImport, CoClass(typeof(Foo)), Guid("787C1303-AE31-47a2-8E89-07C7257B1C43")]
interface IFoo {
void Bar();
}
class Foo : IFoo {
public void Bar() {
Console.WriteLine("Oh retado!");
}
}
being used as:
class CoClass...
I have data model classes that contain private fields which are meant to be read-only (via a getter function). These fields are set by my JPA persistence provider (eclipselink) during normal operation, using the contents of the database. For unit tests, I want to set them to fake values from a mockup of the persistence layer. How can I d...
I have a factory method that creates objects to be used in unit tests. These objects all derive from the same base class:
public static <T extends BaseEntity> T modMake(Class<T> clazz)
{
try {
return clazz.newInstance();
} catch (InstantiationException e) {
// Should never happen
throw new AssertionError(...
Following on from this question...I'm trying to unit test the following scenario:
I have a class that allows one to call a method to perform some action and if it fails wait a second and recall that method.
Say I wanted to call a method DoSomething()...but in the event of an exception being thrown by DoSomething() I want to be able to...
I am trying to Mock an object that is being passed into another object, and am having no success. Can someone show me what I am doing wrong?
class Fetcher
def download
return 3
end
end
class Reports
def initialize(fetcher)
@fetcher = fetcher
end
def status
@fetcher.download
end
end
describe Reports do
before...
I am using SqlAlchemy, a python ORM library. And I used to access database directly from business layer directly by calling SqlAlchemy API.
But then I found that would cause too much time to run all my test cases and now I think maybe I should create a DB access layer, so I can use mock objects during test instead of access database di...
Hi,
I am used to using JMock in Java which allows you to specify things such as any(String.class) as an expected argument - which .NET frameworks offer similar functionality?
...
hi,
I'm using NUnit mocks and would like to specify that I expect a call but without saying what the arguments will be for example:
mock.ExpectAndReturn("Equals", true, ANY_ARGUMENT);
Obviously filling in the correct syntax instead of ANY_ARGUMENT.
Is there a way to do this?
If I specify no arguments - NUnit fails the test because ...
I have a class that has a property that I need to stub. I can't pass it as part of the constructor because the object constructing it does not know the parameters of the constructor.
When running unit tests, I want to be able to have the property be created as a stub.
This is what I have tried, but it does not work:
private DeviceMed...
First let me state that, despite being a fairly new practitioner of TDD, I'm pretty much sold on its benefits. I feel like I've progressed enough to consider using mocks and have hit a real brick wall when it comes to understanding where mocks fit in with OOP.
I've read as many relevant posts/articles on the subject as I could find (Fo...