An Early Look at JUnit 4 147
An anonymous reader writes "Elliotte Harold, proclaimed 'obsessive code tester', took an early look at JUnit4 and shows how to best utilize the framework in your own projects. Many feel that this is one of the most important third-party Java libraries ever developed. It promises to simplify testing by exploiting Java 5's annotation feature to identify tests rather than relying on subclassing, reflection, and naming conventions."
More on Elliotte (Score:5, Informative)
He's also a committer on the open source Jaxen [jaxen.org] XPath engine; my static analysis utility PMD [sf.net] is among the many satisfied Jaxen customers.
Re:Where was the headline when NUnit was released? (Score:3, Informative)
For more info on xUnit testing frameworks for many different languages and platforms see (way down the page is a table):
http://www.xprogramming.com/software.htm/ [xprogramming.com]
Cadmann
Re:Testing (Score:3, Informative)
I've also been recently poking at Jmock [jmock.org] and CGLib [sf.net] for my testing system as well.
Jmock's built on top of junit, so it uses the same mechanisms, and can produce test cases the same way (ie, it works in eclipse's junit view :) ).
Using JMock, one can create mock objects for interfaces that expect various functions to be called some number of times with particular sets of arguments. I believe they can even be configured to throw various exceptions
This is handy in the junit sense so that you can test classes in isolation.
Of course, this only works for classes with predefined java interfaces. So toss cglib into the mix, and jmock will happily use that to create mock classes out of concrete classes instead! (basically by using an alternative to the java reflections api). Doesn't require native libraries either, still all java based, and still all opensource.
Like I say, looking very handy for my next major project which we're just finishing the design stage of at uni :).
That said, I haven't tried anything too complex with it yet, and the mock objects toss out some weird error messages if you mistype a function name or parameter :) )
ashridah
Maybe, but it doesn't work with databases... (Score:3, Informative)
Unless your application is database driven.
As of several months ago, when I last looked, there is no easy way to do automated unit testing on an application that requires a existing dataset for each unit.
DBUnit made an attempt but it was far from realistic and did not scale in anyway to the enterprise level. What?? You mean I have to store my schema as XML? That's re-goddamn-tarded.
Everything ends up a kludge that is extremely difficult to maintain. If people have seen different, please share.
Re:I don't know if I am the only one thinking this (Score:5, Informative)
Super off-topic (Score:1, Informative)
With Visual Studio
This is news and it is certainly stuff that matters to nerds. The summary is well written, well linked, and unbias. I also did some searching of slashdot and could not find evidence of the story being a dupe (not that the editors would have noticed).
So why was it rejected?
Re:Java 5, JUnit4 (Score:3, Informative)
Re:Web / GUI (Score:3, Informative)
It only helps you for web apps, though.
Re:Where was the headline when NUnit was released? (Score:2, Informative)
In that sense, all the other xUnit stuff is decidedly a descendant of JUnit.
been there, done that (Score:3, Informative)
Like JTiger [jtiger.org] has done for ages?
Why not just use TestNG? (Score:4, Informative)
Unless JUnit is going to add quite a few more features, it still won't be nearly as flexible as TestNG. I think the JUnit developers are stuck on this idea of independent tests, which certainly has its merits but ends up excluding a lot of powerful options or forcing you to use ugly workarounds.
TestNG is more of an all-purpose testing framework, equally adept at unit testing as well as higher level functional testing. As a developer, I want to be able to test things in whatever way fits the task at hand. For instance, sometimes it's easier or arguably makes more sense to test a multi-step process (say, user registration and verification) in a defined order. This is possible with JUnit, but it definitely goes against the grain of the framework, which does not support test dependencies and therefore doesn't support ordered tests. I don't appreciate being penalized by a framework because its developers have a very specific concept of "pure" unit testing.
Perhaps I should elaborate: I'm sure the JUnit developers know far more about unit testing that I do, but I want to write more than just unit tests. I'm perfectly happy to admit to writing functional and acceptance tests (and even tests that talk to a real database) in addition to true, pure unit tests. I understand why the differences should be recognized, but the fact remains that JUnit simply does not accomodate a broader view of testing.
I hate to be critical of something that's brought so much improvement to how we write code (JUnit), but I think we've all learned a lot about unit and other types of testing and it's time to move on to something that embodies those lessons.
Re:Where was the headline when NUnit was released? (Score:3, Informative)
RE: Too bad (Score:2, Informative)
Why bother with GUI testrunners when you can just create a nice set of webpages containing your JUnit results in detail? That way anyone with a web browser can take a look. In your Ant buildfile, have JUnit output the results as XML, and use the junitreport task [apache.org] to automagically transform it to HTML.
For a small amount of effort, you'll get something like this [apache.org].