mocking

How to write unit tests for SerialPort

I know the short answer is Mocks, but any examples would be good. I need to be able to test the following: 1. Connect/disconnect 2. Receive data at set intervals 3. Pause in data transmission, causing my class to attempt reconnect 4. Test that events are firing when expected. As a start, I was thinking of defining an interface, which w...

EasyMock: Void Methods

I have a method that returns void in a class that is a dependency of the class I want to test. This class is huge and I'm only using this single method from it. I need to replace the implementation of this method for the test as I want it to do something different and I need to be able to access the parameters this method receives. I c...

Unit tests for code accessing ActiveDirectory

What's the best way to unit test an application accessing the ActiveDirectory and/or mock the dependencies to the AD? All the required types such as DirectorySearcher and DirectoryEntry don't appear to be easily mockable. We've got methods like FindByUserName() and would like to (unit) test them. ...

Mock svn instance for testing svnkit tests

Hi all A project I'm working on interacts heavily with Subversion, using svnkit. Are there any examples on running a mock in-memory svn instance, to help facilitate testing etc? Cheers Marty ...

Mocking Spring MVC BindingResult when using annotations

I'm migrating a Spring MVC controller to use the newer style annotations, and want to unit test a controller method that validates a command object (see simple example below). @RequestMapping(method = RequestMethod.POST) public String doThing(Command command, BindingResult result, HttpServletRequest request, HttpSer...

Easy way to fill up ResultSet with data

Dear All, I want to mock a ResultSet. Seriously. I'm refactoring one big complicated piece of code which is parsing data from ResultSet, and I want my code to behave identically. So, I need to write a unit test for the piece being refactored to be able to test this. After googling I came up with 2 ideas: Use EasyMock, write looooong ...

What book on TDD for C# with treatment of Mocks

Can you recoment a book on on Unit Testing and TDD for C# with at least some treatment of Mock Objects? I have seen this question but it does not seem to mention mocking. ...

Should static classes be avoided because it makes Dependency Injection Difficult?

Somebody tasked with creating a "Core" set of libraries created a set of static classes providing all sorts of utilities from logging, auditing and common database access methods. I personally think this stinks because we now have a Core set of libraries that are hard to test because I can't mock / stub these classes or do any injection...

How should I verify a log message when testing Python code under nose?

Hi all I'm trying to write a simple unit test that will verify that, under a certain condition, a class in my application will log an error via the standard logging API. I can't work out what the cleanest way to test this situation is. I know that nose already captures logging output through it's logging plugin, but this seems to be i...

How to unit-test a NextPasswordChangeDate function against the Active Directory

Hello I am working on a project using the Active Directory, intensively. I set up a few unit tests for several things against the AD, some of which I achieve using mocked objects, some which I achieve through real calls against the AD. As one of the functions of my project, I have to retrieve a so called "user profile". This user profi...

Mocking framework for .Net fx 1.1?

Anyone have any ideas what I can do? Please reserve commenting about using 1.1 still, it's out of my hands :( ...

Testing SQL query on Oracle which includes a remote database

Our development databases (Oracle 9i) use a remote database link to a remote shared database. This decision was made years ago when it wasn't practical to put some of the database schemas on a development machine - they were too big. We have certain schemas on the development machines and we make the remote schemas look local by using ...

Automatic stubbing in java word. What to use?

Hi, I have huge class that I need to build stub for. To give you picture it is Messages class of the GWT. Often this is class with dozens of methods that return String. With JMock I can do stubbing, but I will end with allowing each method... This is not something that I would like to see. Is there something that will automatically b...

How to stub/mock JDBC ResultSet to work both with Java 5 and 6?

Hi, I'm testing some of my classes working with JDBC statements etc and now I got problem with JDBC ResultSet interface: The software should run both with Java 5 and Java 6 and hence the tests should also be run with both versions. Unfortunately Java 6 has introduced a bunch of new methods (which is still not a big deal) that return a ...

Using Spring to inject EasyMock mocks causes ClassCastException

I am trying to get Spring to inject EasyMock mocks in my unit tests. In my applicationContext.xml, I have this: <bean id="mockService" class="org.easymock.EasyMock" factory-method="createMock" name="MockService"> <constructor-arg index="0" value="my.project.Service"/> </bean> In my unit test I have this: @Autowired @Qualifier(...

Mocking a method that returns a sealed class in RhinoMocks

Running this code: _foo = MockRepository.GenerateStub<IBar>(); _foo.Stub(x => x.Foo()).Return("sdf"); When public interface IBar { string Foo(); } public class Bar : IBar { public string Foo() { throw new NotImplementedException(); } } throws NotSupportedException - "Can't create mocks of sealed classes". I under...

Test and Mock framework for Java and .NET

I'd like to know your thoughts about test/mocking frameworks that are widely used and have a good level of compatibility between Java and .NET. I mean, I want to learn those tools to use in a .NET project, but I still wanna be able to apply that knowledge in Java projects. I know there're many questions about test/mocking frameworks to...

Setting expectations on Sub (not Function) in VB.NET using Rhino Mocks

I remember that to set expectations on methods that return void in C# one has to write: mockedRepository.Expect(() => mr.AddUser(someUser)).DoOtherStuff() where AddUser returns void. How to achieve the same in VB.NET? EDIT: I've found similar question. May be helpful: How to mock a method with Rhino Mocks in VB.NET . ...

Mocking HttpPostedFileBase with Rhino Mocks

I'm new to mocking so I need a bit of guidance on how to mock HttpPostedFileBase with Rhino Mocks. I am trying to verify that my ToByteArray() extension works as expected and this is what I have so far: [Test] public void Should_return_a_byte_array_with_a_length_of_eleven() { // Arrange var stream = new MemoryStream(System.Text.En...

When is it preferable to store data members as references instead of pointers?

Let's say I have an object Employee_Storage that contains a database connection data member. Should this data member be stored as a pointer or as a reference? If I store it as a reference, I don't have to do any NULL checking. (Just how important is NULL checking anyway?) If I store it as a pointer, it's easier to setup E...