Skip to main content

Posts

Showing posts from July, 2008

How to use EasyMock's expect method when unit testing

I recently blogged about getting started with EasyMock - a simple framework for taking the pain out of creating and using mock objects when unit testing your java code. In the example I showed that we were expecting the next() method to be called and we wanted the mock ResultSet to return false: expect(mockResultSet.next()).andReturn(false); What I didn't explain was that you use the expect() method when you are expecting the mock to return a value. If the method doesn't return a value (such as ResultSet.close() ) then there is no need to wrap it in an expect() method call: mockResultSet.close(); Remember: any methods that you call on your mock prior to the replay() method call are setting up it's expectations not actually calling the methods. After the replay() method is called the mock is in 'live' mode, recording activity and returning any predefined values when it's methods are called. So here is the same example with the additional expected close()

Getting started with Java Mock Objects using EasyMock

If you are familiar with unit testing and test driven development then you are most probably aware of Mock Objects . The EasyMock website states that: A Mock Object is a test-oriented replacement for a collaborator. It is configured to simulate the object that it replaces in a simple way. In contrast to a stub, a Mock Object also verifies whether it is used as expected. Mock Objects were introduced at XP 2000 by Tim Mackinnon, Steve Freeman and Philip Craig with the Endo-Testing: Unit Testing with Mock Objects paper. So how do you use them? Basically you want to test some code that depends on a number of other objects. Some of these objects might have unwanted side effects like talking to a database, or accessing an external URL. Rather than passing in the real implementation (with the above side effects) you would pass in a mock or stub instead. The mock can be pre-wired to expect a number of calls to it's methods from the code under test and will record these calls for ver

How to enable Line In Pass Through to your speakers with Realtek Audio on Windows XP

If you are having problems hearing anything after you have plugged a sound source into the 'Line In' socket of a Realtek soundcard (or motherboard onboard sound) then read on... Plug your MP3 player (or other sounds source) into the 'Line In' socket and then go to the control panel and start the 'Realtek HD Sounds Effects Manager'. If you click the 'Audio I/O' tab you should see something like: The highlighted part indicates that the Realtek HD Audio Manager knows that you have plugged a 'Line In' device in. You should now be able to record what is being played but you most probably won't be able to hear it! A lot of audio cards give you the option of passing the line in through to the line out so that you can hear it on your speakers but this isn't the case with the Realtek audio. What you have to do is ensure that the 'Rear Blue In' channel is not muted and has some volume as well as the 'Line In': It took quite a bit