This is what I have:
it "should be able to get a valid directory path" do
@asset.some_file_path.should == "/something/test.jpg"
end
The problem is that some_file_path returns "/not_here_yet.jpg" if there is no existing file.
def some_file_path
if File.exists(self.my_image_path)
return my_image_path
else
return "/not_...
I google around unit testing LINQ to SQL and people are using MockDatabase class where we have list and add data to those Lists.
This will fit in the scenarios where we dont have relationships.
I am behind using some data or mdf file in the unit test project which will have the same structure as like my actual database with all relation...
If I have a method that calls itself under a certain condition, is it possible to write a test to verify the behavior? I'd love to see an example, I don't care about the mock framework or language. I'm using RhinoMocks in C# so I'm curious if it is a missing feature of the framework, or if I'm misunderstanding something fundamental, or i...
I am creating a repository that exposes IQueryable. What is the best way to mock this out for my unit testing?
Since I am using RhinoMocks for the rest of my mock objects, I tried to do the following:
IQueryable<MyObject> QueryObject =
MockRepository.GenerateStub<IQueryable<MyObject>>();
This doesn't work though so I tried doing...
When unit testing a codebase, what are the tell-tale signs that I need to utilise mock objects?
Would this be as simple as seeing a lot of calls to other objects in the codebase?
Also, how would I unit test methods which don't return values? So if I a method is returning void but prints to a file, do I just check the file's contents?
...
Please take a look at the following article about testing with mocks
So there is an example of unit test with mock objects. As you can see, the test is written for GetPersonByID method. In the IPersonServices interface there is another method: List<Person> GetPersons();
Can anyone tell me how a Test method on this service should look ...
Hi, I was trying to mock an interface and I got the next expection:
System.TypeLoadException: System.TypeLoadException: Signature of the body and declaration in a method implementation do not match
I figured out later that my problem was a function that I have defined in my interface:
IList<T> GetAll<T>() where T : class, new();
...
Hi, I have an interface definded like this:
public interface IDatabase{ void Get<TTypeToFetch> ();}
and when I try to do:
Mockery mockery = new Mockery();
IDatabase db = mockery.NewMock<IDatabase>();
I get the following error:
System.TypeLoadException: System.TypeLoadException: Signature of the body and declaration in a method...
I am toying with the idea of unit testing a tier within my application using the Mock Object Pattern. The problem i'm facing is how to switch from my mock objects to the real objects when not unit testing.
My initial reaction was to reference two libraries (one containing the real objects and one with the mocks) and use conditional comp...
I am using an external library which allows logging using StreamWriter - now I want to add some handling based on the content of the logging. As I want to avoid to loop through the log file, I would like to write a class which inherits from StreamWriter.
What is the best way to inherit from StreamWriter with as few re-implementations of ...
How to make mock void methods.I performed observer pattern but i cant mock with mockito because i dont know the mock way with mockito.And i search from the internet i cant find properly sample.
My class looks like
public class World{
List<Listener> listeners;
void addListener(Listener item)
{
listeners.add(item);
}
void doActio...
If I was to write a mocking library, how would this work (in other words, how do "they work?)?
One of the things which I wonder is that you are always setting expectations so really you need to compare the expectation to what the method does at runtime, so I assume reflection (resolving types at runtime) is required.
Also, when using t...
I'm trying to think of a good way to clean up my controllers to make them more testable without having to rely on a constant database connection. I thought I had a decent start by abstracting away my object context with an IObjectContext. This works well for the context, but my next problem is that I have a generic repository that I use ...
Hi all,
I have a method that i want to mock that takes an array as a argument. In a real call, the method would modify this array and the resultant array would be use further along in code.
What i tried to do was pass in array to the mocked method call, that had values that would be valid when the array is used again. However what i fin...
Hi,
I'm new to mock testing.
I want to test my Service method CorrectionService.CorrectPerson(Long personId).
The implementation is not yet written but this it what it will do:
CorrectionService will call a method of AddressDAO that will remove some of the Adress that a Person has. One Person has Many Addresses
I'm not sure what the ...
Hi guys,
I'm really getting to TDD recently, and after reading Kent Beck's book on Test Driven Development, I've still got many questions around test design in my mind.
One of the issues I'm currently having is the use of Mock objects. Take below a very simple that generates a report:
public string MakeFinancialReport()
{
...
I have a preexisting Interface...
public interface ISomeInterface
{
void SomeMethod();
}
and I've extended this intreface using a mixin...
public static class SomeInterfaceExtensions
{
public static void AnotherMethod(this ISomeInterface someInterface)
{
// Implementation here
}
}
I have a class thats callin...
During this semester my professor tried to convince us why is good to use unit tests during development, why is it good to validate data(Microsoft Application Block) and also he told us about using mocking(RhinoMocks) in order to test our methods when we didn't had access to a database.
I had to do some unit tests with mocking and in or...
Hello,
I have a class API which has full code coverage and uses DI to mock out all the logic in the main class function (Job.Run) which does all the work.
I found a bug in production where we werent doing some validation on one of the data input fields.
So, I added a stub function called ValidateFoo()... Wrote a unit test against this...
Hello,
I am a bit confused
from wiki:
"This means that a true mock... performing tests on the data passed into the method calls as arguments."
I never used unit testing or mock framework. I thought unit tests are for automated tests so what are mock tests for?
What I want is a object replacing my database I might use later but still ...