From: Phil Muldoon <pmuldoon@redhat.com>
To: Frysk Hackers <frysk@sourceware.org>
Subject: How to test fail conditions in TestCase?
Date: Mon, 16 Apr 2007 18:55:00 -0000 [thread overview]
Message-ID: <4623C696.1000506@redhat.com> (raw)
Hi
I've been added "expected normal" results to test cases as normal, but
I've just started "expected fail" conditions for the test case of
CorefileByteBuffer. I was reminded again, when writing previous tests, I
was unsure of how to write these properly. Here is what I do now.
For a normal, expected pass situation, something like:
CorefileByteBuffer coreBuffer = new CorefileByteBuffer(new
File(Config.getPkgDataDir (),
"test-core"));
// Set the corefile carat to memory address 0x00170000L
coreBuffer.position(0x00170000L);
assertEquals("Peek a byte at 0x00170000",0x7f,coreBuffer.get());
assertEquals("Peek a byte at 0x00170001",0x45,coreBuffer.get());
assertEquals("Peek a byte at 0x00170002",0x4c,coreBuffer.get());
assertEquals("Peek a byte at 0x00170003",0x46,coreBuffer.get());
assertEquals("Peek a byte at 0x00170004",0x01,coreBuffer.get());
But for an expected fail (ie an exception should be thrown or an error
condition detected) something like:
// Test reading at position 0. In this core file there is no
// segment at position 0 (in our case for this bytebuffer, the
// position within the buffer should equal the memory address access.)
// This should always fail!
coreBuffer.position(0);
try
{
assertEquals("Peek a byte at 0x00170000",0x7f,coreBuffer.get());
}
catch (RuntimeException e)
{
return;
}
fail(".get() read at position 0 should have failed but didn't!");
}
Is that the "right" way to do above? Is there a "right" way?
Regards
Phil
next reply other threads:[~2007-04-16 18:55 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-04-16 18:55 Phil Muldoon [this message]
2007-04-16 19:13 ` Kris Van Hees
2007-04-16 19:32 ` Mark Wielaard
2007-04-16 21:40 ` Phil Muldoon
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=4623C696.1000506@redhat.com \
--to=pmuldoon@redhat.com \
--cc=frysk@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).