Exception happening on unexpected line during failing test

Jan 19, 2010 at 11:29 PM
Edited Jan 19, 2010 at 11:32 PM

I'm just beginning to use NBehave (0.4.5.183).  I'm writing my project in C# using Visual Studio 2005. I put the source up on github at:

git://github.com/JeffHoover/T-BDD-Mandlebrot.git

I run NBehave as follows:

nbehave-console.exe /nologo
"C:\Documents and Settings\Jeff\My Documents\agile\katas\t-bdd-mandlebrot\t-bdd-mandlebrot\bin\Debug\t-bdd-mandlebrot.exe"
/sf="C:\Documents and Settings\Jeff\My Documents\agile\katas\t-bdd-mandlebrot\t-bdd-mandlebrot\complex_numbers_operations.feature"

I have one Given, and three Then/When pairs.

Given two complex numbers with components: real 6, imaginary 7 and real 2, imaginary -1

When I add them
Then I should get a complex number with components: real 8, imaginary 6

When I subtract the second from the first
Then I should get a complex number with components: real 4, imaginary 8

When I multiply them
Then I should get a complex number with components: real 1, imaginary 1

I'm test driving, I'm at the point where the third Then/When pair is failing. If I take it out, the first two pass as expected. The problem I'm having is that NBehave is telling me that there's an exception at a line in a passing test. It's complaining about line 30:

Extensions.ShouldEqual<Complex>(result, new Complex(rr,ii));

when the failing assertion is at actually at line 54:

Extensions.ShouldEqual<double>(result.real, rr);

If I comment out line 30, the third Then/When pair (incorrectly) passes. Can anyone tell me what I'm doing wrong?

I'm also open to suggestions about my code/scenario - as I said, I'm just learning this way of working. Thanks!

The output from my run is below:


C:\Program Files\NBehave\0.4.5.183>go

Scenario: 1.complex_numbers_operations
Given two complex numbers with components: real 6, imaginary 7 and real 2, imaginary -1
When I add them
Then I should get a complex number with components: real 8, imaginary 6
When I subtract the second from the first
Then I should get a complex number with components: real 4, imaginary 8
When I multiply them
Then I should get a complex number with components: real 1, imaginary 1 - FAILED


F
Scenarios run: 1, Failures: 1, Pending: 0
Steps 7, failed 1, pending 0

Failures:
1)  (1.complex_numbers_operations) FAILED
  NUnit.Framework.AssertionException :   Expected: <Mandlebrot.Complex>
  But was:  <Mandlebrot.Complex>

   at NUnit.Framework.Assert.That(Object actual, IResolveConstraint expression,
String message, Object[] args)
   at NUnit.Framework.Assert.That(Object actual, IResolveConstraint expression)
   at NBehave.Spec.NUnit.Extensions.ShouldEqual[T](T actual, T expected)
   at Mandlebrot.complex_numbers_operations.complt(Double rr, Double ii) in C:\D
ocuments and Settings\Jeff\My Documents\agile\katas\t-bdd-mandlebrot\t-bdd-mandl
ebrot\complex_numbers_operations.cs:line 30

C:\Program Files\NBehave\0.4.5.183>

 

Coordinator
Jan 20, 2010 at 1:52 PM

Your three methods complt, complt1, complt2 all have exactly the same signature on their attribute:  [Then ("I should get a complex number with components: real $rr, imaginary $ii")]
So NBehave finds 3 matches to your Then row in the text file (and will use the last match iirc).

Jan 21, 2010 at 2:31 AM
Lazydev wrote:

Your three methods complt, complt1, complt2 all have exactly the same signature on their attribute:  [Then ("I should get a complex number with components: real $rr, imaginary $ii")]
So NBehave finds 3 matches to your Then row in the text file (and will use the last match iirc).

Thank you! Now I understand what's happening.

Can you tell me a better way to structure the tests I'm doing?