Test/Unit question

S

Steve Tuckner

This is a multi-part message in MIME format.

------=_NextPart_000_0211_01C3A211.0AC767D0
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: 7bit

Is there any easy way to have a test/unit failure display the call stack
of the failure? Typically it displays the test name and test case but
not where in the test function exactly if the assertion was in a
function called by test function. So if my test case is as below:

require "test/unit"

class SillyTest < Test::Unit::TestCase
def check_result(x1, x2, y1, y2)
assert_equal(x1, x2)
assert_equal(y1, y2)
end

def test_values_1
check_result(1,2,3,4)
check_result(1,2,4,5)
end

def test_values_2
check_result(1,2,4,5)
check_result(1,2,5,6)
end
end

and my output is:

1) Failure!!!
test_values_1(SillyTest) [SillyTest.rb: 5]:
<1> expected but was
<2>


I don't know where the failure originated in the test case. It could be
line 10 or 11.

Thanks for a great tool!

Steve Tuckner


------=_NextPart_000_0211_01C3A211.0AC767D0
Content-Type: text/html;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>



<META content=3D"MSHTML 6.00.2733.1800" name=3DGENERATOR></HEAD>
<BODY>
<DIV><SPAN class=3D656303719-03112003><FONT face=3DArial size=3D2>Is =
there any easy=20
way to have a test/unit failure display the call stack of the failure? =
Typically=20
it displays the test name and test case but not where in the =
test&nbsp;function=20
exactly if the assertion was in a function called by test function. So =
if my=20
test case is as below:</FONT></SPAN></DIV>
<DIV><SPAN class=3D656303719-03112003><FONT face=3DArial=20
size=3D2></FONT></SPAN>&nbsp;</DIV>
<DIV><SPAN class=3D656303719-03112003><FONT face=3DArial =
size=3D2>require=20
"test/unit"</FONT></SPAN></DIV>
<DIV><SPAN class=3D656303719-03112003><FONT face=3DArial=20
size=3D2></FONT></SPAN>&nbsp;</DIV>
<DIV><SPAN class=3D656303719-03112003><FONT face=3DArial size=3D2>class =
SillyTest &lt;=20
Test::Unit::TestCase</FONT></SPAN></DIV>
<DIV><SPAN class=3D656303719-03112003>&nbsp;&nbsp;&nbsp; <FONT =
face=3DArial=20
size=3D2>def check_result(x1, x2, y1, y2)</FONT></SPAN></DIV>
<DIV><SPAN =
class=3D656303719-03112003>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
assert_equal(x1, x2)</SPAN></DIV>
<DIV><SPAN =
class=3D656303719-03112003>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
assert_equal(y1, y2)</SPAN></DIV>
<DIV><SPAN class=3D656303719-03112003>&nbsp;&nbsp;&nbsp; =
end</SPAN></DIV>
<DIV><SPAN class=3D656303719-03112003><FONT face=3DArial=20
size=3D2></FONT></SPAN>&nbsp;</DIV>
<DIV><SPAN class=3D656303719-03112003>&nbsp;&nbsp;&nbsp; <FONT =
face=3DArial=20
size=3D2>def test_values_1</FONT></SPAN></DIV>
<DIV><SPAN =
class=3D656303719-03112003>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
<FONT face=3DArial size=3D2>check_result(1,2,3,4)</FONT></SPAN></DIV>
<DIV><SPAN class=3D656303719-03112003>
<DIV><SPAN =
class=3D656303719-03112003>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
<FONT face=3DArial=20
size=3D2>check_result(1,2,4,5)</FONT></SPAN></DIV>&nbsp;&nbsp;&nbsp; =
<FONT=20
face=3DArial size=3D2>end</FONT></SPAN></DIV>
<DIV><SPAN class=3D656303719-03112003><FONT face=3DArial=20
size=3D2></FONT></SPAN>&nbsp;</DIV><SPAN =
class=3D656303719-03112003><FONT face=3DArial=20
size=3D2>
<DIV><SPAN class=3D656303719-03112003><FONT face=3DArial size=3D2>
<DIV><SPAN class=3D656303719-03112003>&nbsp;&nbsp;&nbsp; <FONT =
face=3DArial=20
size=3D2>def test_values_2</FONT></SPAN></DIV>
<DIV><SPAN =
class=3D656303719-03112003>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
<FONT face=3DArial size=3D2>check_result(1,2,4,5)</FONT></SPAN></DIV>
<DIV><SPAN class=3D656303719-03112003>
<DIV><SPAN =
class=3D656303719-03112003>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
<FONT face=3DArial=20
size=3D2>check_result(1,2,5,6)</FONT></SPAN></DIV>&nbsp;&nbsp;&nbsp; =
<FONT=20
face=3DArial size=3D2>end</FONT></SPAN></DIV></FONT></SPAN></DIV>
<DIV>end</FONT></SPAN></DIV>
<DIV><SPAN class=3D656303719-03112003><FONT face=3DArial=20
size=3D2></FONT></SPAN>&nbsp;</DIV>
<DIV><SPAN class=3D656303719-03112003><FONT face=3DArial size=3D2>and =
my output=20
is:</FONT></SPAN></DIV>
<DIV><SPAN class=3D656303719-03112003><FONT face=3DArial=20
size=3D2></FONT></SPAN>&nbsp;</DIV>
<DIV><SPAN class=3D656303719-03112003><FONT face=3DArial =
size=3D2>&nbsp; 1)=20
Failure!!!<BR>test_values_1(SillyTest) [SillyTest.rb: 5]:<BR>&lt;1&gt; =
expected=20
but was<BR>&lt;2&gt;<BR></DIV>
<DIV></FONT></SPAN><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><SPAN class=3D656303719-03112003><FONT face=3DArial =
size=3D2>I&nbsp;don't know=20
where the failure originated in the test case. It could be line 10 or=20
11.</FONT></SPAN></DIV>
<DIV><SPAN class=3D656303719-03112003><FONT face=3DArial=20
size=3D2></FONT></SPAN>&nbsp;</DIV>
<DIV><SPAN class=3D656303719-03112003><FONT face=3DArial =
size=3D2>Thanks for a great=20
tool!</FONT></SPAN></DIV>
<DIV><SPAN class=3D656303719-03112003><FONT face=3DArial=20
size=3D2></FONT></SPAN>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>Steve Tuckner</FONT> =
<BR></DIV></BODY></HTML>

------=_NextPart_000_0211_01C3A211.0AC767D0--
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,930
Messages
2,570,072
Members
46,522
Latest member
Mad-Ram

Latest Threads

Top