mocking

Mocking virtual readonly properties with moq.

I couldn't find a way to do this, though this can be done by hand so why not with moq? ...

Can Python's MiniMock create mock of functions defined in the same file?

I'm using the Python MiniMock library for unit testing. I'd like to mock out a function defined in the same Python file as my doctest. Can MiniMock handle that? The naive approach fails: def foo(): raise ValueError, "Don't call me during testing!" def bar(): """ Returns twice the value of foo() >>> from minimock impor...

Using IoC for UnitTesting

How can a Ioc Container be used for unit testing? Is it useful to manage mocks in a huge solution (50+ projects) using IoC? Any experiences? Any c# libraries that work well for using it in unit tests? ...

How do I setup a call of an Equals with a specific type overriding the Equals in MoQ?

Working with the fine mocking-framework MoQ, I came across a somewhat surprising facet (and I don't like surprises). I'm mocking out a class which should be added to a collection after a method-call, like so: public class SomeClass{ } public class Container { private List<SomeClass> classes = new List<SomeClass>(); public IEnumerab...

How can I validate exits and aborts in RSpec?

I am trying to spec behaviors for command line arguments my script receives to ensure that all validation passes. Some of my command line arguments will result in abort or exit being invoked because the parameters supplied are missing or incorrect. I am trying something like this which isn't working: # something_spec.rb require 'somet...

What are the ideal Unit Test Cases for different layers in repository pattern.

can someone suggest the ideal Unit test cases that may fit in across each of the layers . (which otherwise can be called as a standard). for instance, in an ASP.NET MVC applictaion using a Repository pattern - Controller - can assert for View names and format of the data returned to the views , from the controller action methods( i ...

c#: How can I verify methods are called in a certain order?

I have the following class: public class Script { IPrinter _printer; public Script(IPrinter printer) { _printer = printer; } public void Print(TextWriter writer) { _printer.PrintComment(writer, "lolz"); writer.WriteLine("omg this complicates things"; _printer.PrintSpecial(writer)...

What are the good frameworks for unit-testing and mock objects in Perl?

What frameworks and tools would you recommend for unit-testing and mock objects in Perl? I have an existing Perl application, that mainly does database access, reading and writing files. The application is basically a batch job type of application, it reads in bunch of stuff from files and database and writes a bunch of new files and so...

What is wrong with Stubs for unit testing?

I just watched this funny YouTube Video about unit testing (it's Hitler with fake subtitles chewing out his team for not doing good unit tests--skip it if you're humor impaired) where stubs get roundly criticized. But I don't understand what wrong with stubs. I haven't started using a mocking framework and I haven't started feeling the...

Mocking a Hibernate custom value type

I have a simple hibernate mapping file that makes use of a custom value type for one of the fields. The custom value type contains some reasonably complex business logic. I would like to be able to unit test my object persistence without the custom value type's logic. Is there any way to mock out the custom value type? I have seen a ...

Javascript mocking framework - Jack example.

Hi all: I'm currently having troubles integrating Jack into my QUnit. Besides from not knowing where to start, I'm also confused on how to actually use it (Jack). There aren't a great deal of examples on the web so I was wondering if anyone who have experience in using Jack to mock AJAX calls/general Javascript can show me an example ...

Mocking / Testing a core object in my system

I've been asked to work on changing a number of classes that are core to the system we work on. The classes in question each require 5 - 10 different related objects, which themselves need a similiar amount of objects. Data is also pulled in from several data sources, and the project uses EJB2 so when testing, I'm running without a con...

Is it a good idea to use T4 to code-gen mock objects for interfaces?

I'm familiar with unit testing, but am still learning about mocks and mocking frameworks. I get the ideas (I think), but the syntax still seems a little foreign. I'm considering creating some T4 templates that automatically generate mock implementations of interfaces and classes. Using a combination of generics and extension methods, thi...

groovy mocks with abstract methods

I have a Java object called Parameter and I'm trying to mock it using groovy. Parameter is an abstract class with 1 abstract method. It also has a non-abstract method called getName(). I'm trying to mock it as follows in Groovy: def p1 = [name:{"p1Name"}] as Parameter But I get a runtime error because I don't implement the abstract m...

DB connection failed while testing

Hi, I have an asp.net mvc application, which uses the default user database. It all works pretty well, but I would like to create some tests for it. I Have a test project, I immediately stumble upon an exception The specified named connection is either not found in the configuration, not intended to be used with the EntityClient provide...

How to use the MOQ library to mock an ENum

I am having an issue using the Moq library to mock an Enum within my project. I am trying to test a class and one of the methods accepts an ENum. Is there any way to do this? Here is the Enum I am trying to mock: public enum PermissionType { Create = 0, Read = 1, Update = 2, Delete = 3, } Here is the code I am trying ...

Database Mocking on a large system in Silverlight and RIA Services

I am using Silverlight, Ria, and the Silverlight Testing Framework. I am trying to build a mock database and have run into a few issues. First the example on the RIA site does not use the silverlight testing framework so I am not able to use it. Second The other example that I have tried does not seem very scalable. Since I need to mo...

check for (the absence of) `puts` in RSpec

I am using rspec for my test in a ruby project, and I want to spec that my program should not output anything when the -q option is used. I tried: Kernel.should_not_receive :puts That did not result in a failed test when there was output to the console. How do I verify the absents of text output? ...

Mocking FormsIdentity.Ticket.UserData with Moq

As part of a unit test I am trying to mock the return value of FormsIdentity.Ticket.UserData The following will NOT work but it should give an idea of what I am trying to do: var principal = Mock<IPrincipal>(); var formsIdentity = Mock<FormsIdentity>(); formsIdentity.Setup(a => a.Ticket.UserData).Returns("aaa | bbb | ccc"); principal.S...

Is it good practice to have a table referenced by two different entities?

I am building a application with these patterns: Silverlight, RIA, EF, Prism, SL Unit Testing. This project will have lots of entities and lots of modules referencing those entities. Each entity is in its own RIA Service Library along with the RIA domain service and associated metadata. I am running into problems when I reference a ce...