The Artima Developer Community
Sponsored Link

Java Community News
JUnit 4.4 Comes with a Few Assumptions, Theories, and Some New Syntax

19 replies on 2 pages. Most recent reply: Jul 25, 2007 11:51 AM by David Saff

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 19 replies on 2 pages [ « | 1 2 ]
David Saff

Posts: 9
Nickname: dsaff
Registered: Nov, 2005

Re: JUnit 4.4 Comes with a Few Assumptions, Theories, and Some New Syntax Posted: Jul 23, 2007 2:08 PM
Reply to this message Reply
Advertisement
> * There problem to me is not that JUnit has a new API as
> it still supports the old one. My problem is that it's got
> a new dependency. And with that, my project all of a
> sudden has a new dependency to some Hamcrest party, too!

The hamcrest classes are included in the JUnit jar. You can ignore them without consequence.

David Saff

David Saff

Posts: 9
Nickname: dsaff
Registered: Nov, 2005

Re: JUnit 4.4 Comes with a Few Assumptions, Theories, and Some New Syntax Posted: Jul 23, 2007 2:13 PM
Reply to this message Reply
> > JUnit now includes the ability to express "assumptions"
> :
> > With this release, a failed assumption will lead to the
> > test being marked as passing, regardless of what the
> > code below the assumption may assert. In the future,
> > this may change, and a failed assumption
> may lead to the test being ignored
>
> Is this saying that a new feature is being introduced that
> currently does nothing and whose future behavior
> may become version dependent? It sounds like an
> odd strategy.

It's an unfortunate compromise--ideally, we could have released with failed assumptions leading to ignored tests in this version, but it would have broken current IDE's.

> In addition, I'm wary of a feature that potentially
> may lead to tests being ignored. Unless a test is
> commented out, it would seem to me more logical that tests
> should either pass or fail.

I certainly prefer tests that either pass or fail. However, if a test depends on an environment that is not currently available, it's wrong to have it pass (we don't know the code works), and wrong to have it fail (we don't know that anything's wrong with the code, just a temporary problem with the test setup.)

David Saff

Morgan Conrad

Posts: 307
Nickname: miata71
Registered: Mar, 2006

Re: JUnit 4.4 Comes with a Few Assumptions, Theories, and Some New Syntax Posted: Jul 23, 2007 3:02 PM
Reply to this message Reply
> This is not just an issue with the new API. I hate going
> to a test failure and finding something like:
>
> assertTrue( foo == 42 );
>
> instead of
>
> assertEquals( 42, foo );
>
> Why did the test fail? What was foo? Why should I need
> to go into the debugger just to find out what foo was? I
> always change these to assertEquals().

While I agree with you, and prefer assertEquals(), the message still isn't all that useful. AssertEquals or not, your 1st question, which is the only one that really matters, is UNANSWERED except by examination of the code, logfiles, or debugging.


>
> Someone else suggested using the message for this:
>
> assertTrue( "foo should be 42 but was " + foo, foo == 42
> );
>
> but that is redundant code which increases the maintenance
> cost with no advantage over assertEquals().
>
> The assertEquals() API is more appropriate and the better
> choice. I imagine that this new API will also be the
> better choice, for the same reason.

Morgan Conrad

Posts: 307
Nickname: miata71
Registered: Mar, 2006

Re: JUnit 4.4 Comes with a Few Assumptions, Theories, and Some New Syntax Posted: Jul 24, 2007 9:45 AM
Reply to this message Reply
Trying to be a bit more constructive and positive...

I think James made a good point about using a "real" scripting language. I know next to nothing about scripting languages using the JVM, but if JUnit used them, and used them effectively, that would be a nice incentive to learn some cool new stuff.

David Saff

Posts: 9
Nickname: dsaff
Registered: Nov, 2005

Re: JUnit 4.4 Comes with a Few Assumptions, Theories, and Some New Syntax Posted: Jul 25, 2007 11:51 AM
Reply to this message Reply
> I think James made a good point about using a "real"
> scripting language. I know next to nothing about
> scripting languages using the JVM, but if JUnit used them,
> and used them effectively, that would be a nice incentive
> to learn some cool new stuff.

There have been interesting articles written about using Groovy and JUnit together, such as

http://www.ibm.com/developerworks/java/library/j-pg11094/

Also, there's an article on using Groovy with Popper, the software project that spawned the Theory idea in JUnit 4.4:

http://groovy.codehaus.org/Using+Popper+with+Groovy

Share and enjoy!

Flat View: This topic has 19 replies on 2 pages [ « | 1  2 ]
Topic: Testing GWT Ajax Applications Previous Topic   Next Topic Topic: Geert Bevin on New Features in RIFE 1.6

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use