Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > redesigning JUnit asserts

Reply
Thread Tools

redesigning JUnit asserts

 
 
martinus
Guest
Posts: n/a
 
      08-04-2006
Hello everybody,

I am thinking of writing a replacement / addition for junit's assert
system. I don't like how it is currently done because it is so
inflexible. After playing around a bit, I came up with an API that
looks like this:

public void testInt() {
int num = 4+1;
ensure(num).is(5);
ensure(num).either(4, 5, 6);
ensure(num).between(3, 10);
}

public void testDouble() {
double val = 4 + 0.4;
// an epsilon is mandatory when comparing double
ensure(val).is(4.4, 0.0001);
ensure(val).between(4.3, 4.5);
}

public void testArray() {
int[] a = { 1, 2, 3, 4, 5 };
ensure(a).contains(3);
ensure(a).size().either(5, 6);
ensure(a).contains(2, 3, 4);
ensure(a).contains().either(3, 10, 11);
ensure(a).contains().neither(6, 7, 9);
ensure(a).contains().any(3, 4);
ensure(a).contains().all(3, 4, 5);
ensure(a).isSorted();
ensure(a).isUnique();
}


What do you think about such an API?

Martin
PS: Here is my blog about this
http://martin.ankerl.org/2006/08/02/...junit-asserts/

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Redesigning Network Knowledge Cisco 0 10-31-2009 10:58 AM
Redesigning wireless solution Harrison Midkiff Wireless Networking 2 11-07-2008 02:00 PM
Redesigning my network - what do I need? Julian Regel Cisco 1 06-06-2006 02:48 PM
Redesigning a debug API Maxim Yegorushkin C++ 3 07-13-2005 11:47 AM
Java asserts in interfaces? Ken Java 5 05-22-2004 10:05 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57