|
From: Nat P. <nat...@gm...> - 2006-11-03 23:18:31
|
Catching a root exception and ignoring it is a bad practice. Think of
this as nMock highlighting design issues that need to be addressed.
--Nat.
On 11/3/06, Joselito D. Moreno <joe...@gm...> wrote:
> Hello,
>
> I am not sure whether to report this as a bug or just a gotcha.
>
> Here is the code to reproduce the issue I'm talking about.
>
> This is the class under test:
> public class ServiceDependentClass
> {
> IService service = null;
> public ServiceDependentClass(IService service)
> {
> this.service = service;
> }
>
> public int callService()
> {
> for (int i = 0; i < 3; i++ )
> {
> try
> {
> Console.WriteLine("Calling method [" + i + "]");
> int result = service.doSomething("someParameter");
> }
> catch (Exception)
> {
> }
> }
> return 0;
> }
> }
>
> This is the IService interface:
> public interface IService
> {
> int doSomething(string someParameter);
> }
>
> This is the NUnit test code:
> [TestFixture]
> public class NMock2BugTest
> {
> [Test]
> public void TestBug()
> {
> Mockery mocks = new Mockery();
> IService mockService = mocks.NewMock<IService>();
> ServiceDependentClass classUnderTest = new
> ServiceDependentClass(mockService);
>
> Expect.Once.On(mockService)
> .Method("doSomething")
> .With("someParameter")
> .Will(Return.Value(0));
>
> classUnderTest.callService();
> mocks.VerifyAllExpectationsHaveBeenMet();
> }
> }
>
> The problem with this is that I was expecting this test to fail
> because of the "Expect.Once" call and the class under test actually
> calls the service.doSomething("someParameter") 3 times. Instead, the
> test actually passes when using NUnit because the try-catch(Exception)
> of the class under test that surrounds the service.doSomething() call
> consumes the "NMock2.Internal.ExpectationException: unexpected
> invocation of service.doSomething("someParameter")".
>
> Is this truly a bug or is this just something that users need to be aware of?
>
> Thank you,
>
> Joen Moreno
>
> -------------------------------------------------------------------------
> Using Tomcat but need to do more? Need to support web services, security?
> Get stuff done quickly with pre-integrated technology to make your job easier
> Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
> http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
> _______________________________________________
> NMock-two-dev mailing list
> NMo...@li...
> https://lists.sourceforge.net/lists/listinfo/nmock-two-dev
>
|