mocking

redirect a http request using selenium

This is quite a straight forward question that I can't seem to find a comprehensive answer for. When using Selenium and Selenium proxy, how I can make the proxy catch outgoing xhr requests to specific uri's and modify the destination to a pre-mocked alternative. I found this example form googling, http://www.sonatype.com/people/2009/10/s...

What are strict and non-strict mocks?

I have started using moq for mocking. Can someone explain me the concept of strict and non-strict mocks? How can they can be used in moq? edit: in which scenario do we use which type of mock? ...

How do I unit-test a class that depends on another class to change the state of something?

I have a class A which contains an instance of class B, and function foo of A calls function set of B, which updates the state of B. Here is a code example (in Javascript): A = function () { this.init = function (b) { this.b = b } this.foo = function (val) { this.b.set(val) } this.bar = function () ...

Writing maintainable unit tests with mock objects

This is a simplified version of a class I'm writing a unit test for class SomeClass { void methodA() { methodB(); methodC(); methodD(); } void methodB() { //does something } void methodC() { //does something } void methodD() { //does something } } Whil...

What's the best way to inject a class into another Objective C class for testing purposes?3

Let's say I have a class DataFeed which creates an instance of another class, Parser, as part of its work. i.e. Parser *parser = [[Parser alloc] init]; [parser start]; I'm writing unit tests for DataFeed. I want to substitute a mock for the Parser. I can't work out how best to do this. I'm sure I must be missing something really obvio...

Writing Cucumber features for accessing SVN

I'm developing a tool that accesses SVN by running the command line SVN to get info and export. I'd like to write some Cucumber features so I don't have to keep manually testing but I'd like to mock out the SVN accesses. Should I switch to using a Ruby SVN library and if so, which one? Or is there a fake svn.exe that will provide pr...

Suggestions for a java Mock File (to mock java.io.File)

Does anyone have suggestions for a java mock File object? I Am using a thirdparty class which need to get a java.io.File object as argument. I receive the data for this file in a stream over a webservice (also one of their products). One solution is to write all this data to a file and offer this to the class. This is a solution I don't...

How should I go about mocking calls to XSD data access?

Hey guys I'm trying to introduce Unit testing and TDD into my code (working as one of a team within a large pre-existing project). The project I'm working on uses XSDs to do a lot of the data access (often with no abstraction, i.e. database calls from the .aspx.cs pages, which is another issue I wish to address at some point). My ques...

Dependency injection and mock framework for .net

I am trying to set up expectations on methods of a mocked object in Moq. At the same time, using Ninject, I try to have the kernel return my set up mock whenever a caller wants the corresponding interface. For more clarity, here's some pseudocode Class Car { Void buildChassis() { Engine = ObjectBuilder.get<Iengine>() ...

How to mock a free function in python?

I have a python program with a global function that is painful to test (it needs a large dataset to work properly). What is the best way to get around this while testing functions that call it? I've found that the following works (but it make me feel dirty to use it). module foo: def PainLiesHere(): return 4; #guaranteed to be rando...

How do I create an instance of Oracle.DataAccess.Client.OracleException to use with NMock

I'm using the Oracle.DataAccess.Client data provider client. I am having trouble constructing a new instance of an OracleException object, but it keeps telling me that there are no public constructors. I saw other having the same problem and tried their solutions, but they don't seem to work. Here's my test code: object[] args = { 1, "T...

Moq - verify that no methods were called

This is a unit-test from one of my controllers in an ASP.NET MVC project, using NUnit and Moq: [Test] public void Create_job_with_modelstate_errors_fails() { var job = new JobDto(); this.controller.ModelState.AddModelError("", ""); ActionResult result = this.controller.Create(job); this.jobS...

setting rspec expectations on internal java method calls from jruby

I would love to be able to test java code with rspec under jruby, but can't see how to set expectations on internal java method calls. Given the following java: public class A { public String hi() { return hello(); } public String hello() { return "yo"; } } I would love to be able to do: describe 'A' do it 'should ...

Mock objects - Setup method - Test Driven Development

I am learning Test Driven Development and trying to use Moq library for mocking. What is the purpose of Setup method of Mock class? ...

Using Moles to mock user-made classes

I have searched the forums and all over the web and have not really seen a straight answer for this. I have just been introduced to moles and I read that it can mock any .NET class or function call. However, I am wondering if it is possible to use Moles to mock classes that I have created myself. I have used MOQ before and I have read ...

Mocking wcf in silverlight

I thought that I could create a WCF in and call it in Silverlight. I would inject an interface to the WCF. Then in my unit test I would mock the wcf.... However when I actually got to do this I notice that the interface does not actually have the methods that I am calling. ie myWCF.myfunctionCompleted(myhandler); myWCF.myfunctionAsy...

How to mock web api in unit test

Hi, guys! Now my team working on a client application(c#), and I need to call some web apis that returns xml messages. I want to test the methods that calling these web apis, I know I should use mock objects in unit test. But I can't know how to use it correctly, because this is my first time to introduce unit test to my project. Can som...

Failing in generating moles files for an assembly

I have been looking at Moles for testing my entity framework generated classes and followed the steps outlined in the video and also the tutorial help documents however I am failing at the first step. I get the following error when adding a new moles file item ensuring that the name of the .moles file matches the assembly I have in the ...

What is Mocks Record and Playback?

Hi I have a mock as below: MockRepository mocks = new MockRepository(); ILoanRepository loanRepo = mocks.StrictMock<ILoanRepository>(); SetupResult.For(loanRepo.GetLoanExtended("sdfsdf")).Return(list.AsEnumerable<Loan>()); mocks.ReplayAll(); My question is I have seen the above being use in using statem...

Mocking sockets in java with mockito.

I am trying to mock the following call: s.socket().bind(new InetSocketAddress(serverIPAddress_, serverPort_), 0); so I can test what the rest of the code does when this fails in predictable ways. I use this in my test case: ServerSocketChannel ssc = mock(ServerSocketChannel.class); when(ServerSocketChannel.open()).thenReturn(ssc); do...