|
View:
New views
4 Messages
—
Rating Filter:
Alert me
|
|
|
How would you test this?Hi all,
I'm new to jMock, and am exploring the limits of what it can and can't do. I've recently discovered a pattern that I'm struggling to test with jMock. I'll present an example, and I hope you can show me how you'd test this. I suspect I need to adjust my approach to use jMock in this situation. Thanks in advance! Suppose we have a TrackImpl class, which has an attribute, circuit of type List<Point>. Point has a subclass, SpeedPoint. We wish to add a method to Track, getPreviousSpeedPoint(Point current). The new method will: - return the nearest previous SpeedPoint in circuit to the given parameter. - wrap around to find the nearest previous SpeedPoint. (For example, current could be at index 0, and a SpeedPoint at index circuit.size() - 1. In that case, the SpeedPoint at circuit.size() - 1 should be returned). - return null if no SpeedPoints are found in circuit. - throw an IllegalArgumentException if current is not contained in circuit. I hope this explanation is clear! I'd be interested in seeing your tests for the first couple of bullet points. I feel like I should be stubbing out Track#getCircuit() by subclassing TrackImpl. Is a different approach used with jMock? Many thanks in advance. Cheers, Louis. ---- Louis Rose Research Student Department of Computer Science, University of York, Heslington, York, YO10 5DD, United Kingdom. +44 1904 434762 Twitter: @louismrose --------------------------------------------------------------------- To unsubscribe from this list, please visit: http://xircles.codehaus.org/manage_email |
|
|
Re: How would you test this?I don't see what needs to be mocked in this scenario. What is the
collaborating object that should be replaced? S. On 22 May 2009, at 10:23, Louis Rose wrote: > Hi all, > > I'm new to jMock, and am exploring the limits of what it can and > can't do. I've recently discovered a pattern that I'm struggling to > test with jMock. I'll present an example, and I hope you can show me > how you'd test this. I suspect I need to adjust my approach to use > jMock in this situation. Thanks in advance! > > Suppose we have a TrackImpl class, which has an attribute, circuit > of type List<Point>. Point has a subclass, SpeedPoint. We wish to > add a method to Track, getPreviousSpeedPoint(Point current). The new > method will: > > - return the nearest previous SpeedPoint in circuit to the given > parameter. > - wrap around to find the nearest previous SpeedPoint. (For example, > current could be at index 0, and a SpeedPoint at index > circuit.size() - 1. In that case, the SpeedPoint at circuit.size() - > 1 should be returned). > - return null if no SpeedPoints are found in circuit. > - throw an IllegalArgumentException if current is not contained in > circuit. > > I hope this explanation is clear! I'd be interested in seeing your > tests for the first couple of bullet points. > > I feel like I should be stubbing out Track#getCircuit() by > subclassing TrackImpl. Is a different approach used with jMock? > > Many thanks in advance. > > Cheers, > Louis. > > ---- > Louis Rose > Research Student > Department of Computer Science, > University of York, > Heslington, York, YO10 5DD, United Kingdom. > +44 1904 434762 > Twitter: @louismrose > > --------------------------------------------------------------------- > To unsubscribe from this list, please visit: > > http://xircles.codehaus.org/manage_email > > Steve Freeman Winner of the Agile Alliance Gordon Pask award 2006 http://www.m3p.co.uk M3P Limited. Registered office. 2 Church Street, Burnham, Bucks, SL1 7HZ. Company registered in England & Wales. Number 03689627 --------------------------------------------------------------------- To unsubscribe from this list, please visit: http://xircles.codehaus.org/manage_email |
|
|
Re: How would you test this?Hi Steve,
Thanks for the insightful question - I can use it in other situations to determine whether to use a mock. I agree that, in this case, there doesn't seem to be a collaborating object. This example wasn't as good as I initially thought, I'm sorry. I'm still a little confused about whether jMock can be used to stub out methods on the object under test? I guess not. Does wanting to stub out a method on the object under test indicate a problem with the design? I'll post a better example if I stumble across one. Many thanks for the help. Cheers, Louis. Steve Freeman wrote: > I don't see what needs to be mocked in this scenario. What is the > collaborating object that should be replaced? > > S. > > On 22 May 2009, at 10:23, Louis Rose wrote: >> Hi all, >> >> I'm new to jMock, and am exploring the limits of what it can and can't >> do. I've recently discovered a pattern that I'm struggling to test >> with jMock. I'll present an example, and I hope you can show me how >> you'd test this. I suspect I need to adjust my approach to use jMock >> in this situation. Thanks in advance! >> >> Suppose we have a TrackImpl class, which has an attribute, circuit of >> type List<Point>. Point has a subclass, SpeedPoint. We wish to add a >> method to Track, getPreviousSpeedPoint(Point current). The new method >> will: >> >> - return the nearest previous SpeedPoint in circuit to the given >> parameter. >> - wrap around to find the nearest previous SpeedPoint. (For example, >> current could be at index 0, and a SpeedPoint at index circuit.size() >> - 1. In that case, the SpeedPoint at circuit.size() - 1 should be >> returned). >> - return null if no SpeedPoints are found in circuit. >> - throw an IllegalArgumentException if current is not contained in >> circuit. >> >> I hope this explanation is clear! I'd be interested in seeing your >> tests for the first couple of bullet points. >> >> I feel like I should be stubbing out Track#getCircuit() by subclassing >> TrackImpl. Is a different approach used with jMock? >> >> Many thanks in advance. >> >> Cheers, >> Louis. >> >> ---- >> Louis Rose >> Research Student >> Department of Computer Science, >> University of York, >> Heslington, York, YO10 5DD, United Kingdom. >> +44 1904 434762 >> Twitter: @louismrose >> >> --------------------------------------------------------------------- >> To unsubscribe from this list, please visit: >> >> http://xircles.codehaus.org/manage_email >> >> > > Steve Freeman > Winner of the Agile Alliance Gordon Pask award 2006 > > http://www.m3p.co.uk > > M3P Limited. > Registered office. 2 Church Street, Burnham, Bucks, SL1 7HZ. > Company registered in England & Wales. Number 03689627 > > > > --------------------------------------------------------------------- > To unsubscribe from this list, please visit: > > http://xircles.codehaus.org/manage_email > > --------------------------------------------------------------------- To unsubscribe from this list, please visit: http://xircles.codehaus.org/manage_email |
|
|
Re: How would you test this?On 22 May 2009, at 11:47, Louis Rose wrote:
> Hi Steve, > > Thanks for the insightful question - I can use it in other > situations to determine whether to use a mock. that's one of our core design questions. > I'm still a little confused about whether jMock can be used to stub > out methods on the object under test? I guess not. Does wanting to > stub out a method on the object under test indicate a problem with > the design? We think so, although plenty of others disagree. We prefer to think in terms of small objects composed together, rather than taking slices through larger objects. > Many thanks for the help. Always happy to help. In the meantime, we have a book in progress at http://www.mockobjects.com/book Read and comment via the list :) S. Steve Freeman Winner of the Agile Alliance Gordon Pask award 2006 http://www.m3p.co.uk M3P Limited. Registered office. 2 Church Street, Burnham, Bucks, SL1 7HZ. Company registered in England & Wales. Number 03689627 --------------------------------------------------------------------- To unsubscribe from this list, please visit: http://xircles.codehaus.org/manage_email |
| Free embeddable forum powered by Nabble | Forum Help |