An Early Look at JUnit 4
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."
Maybe I am the only one that understands this too... J-J-J... J UNIT!
After reading this, I noticed it was great but the most obvious omission is a GUI test runner. Fortunately, it is possible that if you want to see a comforting green bar when your tests pass or an anxiety-inducing red bar when they fail. you'll need an IDE with integrated JUnit support such as Eclipse. Neither the Swing nor the AWT test runners will be updated or bundled with JUnit 4.
+1 funny, -2 overrated. Life isn't fair.
As much as the student programmer in me would want to say "Who needs testing, I'm perfect!" I have to admit, this looks impressive. Expected exceptions look pretty useful, although I'm wondering if the syntax is actually proper java coding. If this is an open-source solution, it would be an extremely useful tool to have.
Those are the legion of programmers who learned, certified, and bluffed their way into Java experience. Junit or not--it's going to be very tough landing a job.
Transcend Humanity. Please.
That supported attributed programming years ago? Oh I know, NUnit is a port^H^H^H^Hripoff of JUnit so it doesn't count.
...with JUnit 3, they have to go and improve it. I'll be eating my heart out for a while, because my company will surely not go to Java 5 before Java 6 is out, so these mentioned features will not be available to me. And when they are, I'll have to change my modus operandi.
Actually: Nice work, guys. I'll probably appreciate this once I get a chance to use it and wrap my head around it.
When one person suffers from a delusion, it is called insanity. When many people suffer from a delusion it is called Rel
It would be nice if they synchronized the version numbers so that it was obvious which version of JUnit worked with which version of Java.
I'm looking at the samples and am left scratching my head. I don't see any difference in the various example tests they show. Maybe someone can explain this "annotation" and how it is better (it's certainly more verbose!) than the normal way of doing things.
Jesus saved me from my past. He can save you as well.
Just kidding, JUnit, one with capital U.
The Holy Grail of test automation is Automated Test Generation, in other words the ability to have your application record inputs and outputs in a way that can be easily played back or transformed into a test. Pro/Engineer has this capability. Are there other applications that can do that?
Test 1 2 3 4
For those who haven't heard of him, Elliotte Rusty Harold is a big name in the Java world - he maintains a very popular blog/news site and has written a slew of excellent books.
He's also a committer on the open source Jaxen XPath engine; my static analysis utility PMD is among the many satisfied Jaxen customers.
The Army reading list
How is the parent off topic?
It at least deserves a "funny" mod
"Utilize" would be "use" if you were speaking plain English. And no, using the word "utilize" doesn't make you seem any smarter.
You must be that famous rapper's computer-geek brother, 50 GHz...
Yes! When I saw this headline, I so had my fingers crossed for that to be first post! You rule!
Progress isn't made by early risers. It's made by lazy men trying to find easier ways to do something. -Heinlein
sorry, it's the first thing that sprang to mind upon reading the headline
Rapidly approaching the Zener knee...
Hahaha.. I was gonna say this! C'mon people lighten up a little bit and mark this funny! Naw mean?!
What continues to stun me about the "professional" developers out there is how few do Unit Testing even when it is so easy. People complain about jobs moving offshore and pressure on delivery and people not understanding how hard coding is... but they don't even Unit testing.
If you don't unit test then you aren't a software engineer, you are a typist who understands a programming language.
An Eye for an Eye will make the whole world blind - Gandhi
When and if I will bother to look at Java 5 I will look at JUnit, but this interesting Annotation feature of Java 5 sounds a lot like a precompiler ;)
But why do they not want to ship this new JUnit 4 with the JUnit GUI runner? Did they decide to split the projects?
From the blog I can see that JUnit 4 will not be able to differentiate between the anticipated errors from asserts and unanticipated errors from code - now that will prevent me from converting to JUnit 4 even if I move to Java 5.
You can't handle the truth.
Sadly, I don't know where its from!
But I've heard it uttered in the labs while we were Junit'ing... please, where is it from?
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.
1;
A famous rapper named 50 Cent has a click/gang/group called G-unit. They often say "G-G-G-G-G-G-UNIT" in their songs so people can recognize who they are. Saying "J-J-J-J-J-J-UNIT" is just a play off of this.
Do you mean:
Marcy: "Say it! Say it!!!"
Jefferson: "J-J-J...Joooob"!
?
Any sufficiently advanced intelligence is indistinguishable from stupidity.
If you want to use an advanced testing framework that works with JDK 1.4 and below, check out TestNG, the framework mentioned in the article and which pioneered many of the concepts being implemented in JUnit 4:
http://testng.org/
I was actually thinking more Moon Unit, myself.
The World Wide Web is dying. Soon, we shall have only the Internet.
Writing JUnit tests for Web and GUI applications can be as time consuming, and usually more time consuming than writing the application itself.
Can anyone recommend a good framework for testing these components?
Can anyone tell me why this story was rejected:
.NET 2005 and the .NET 2.0 run-time not even out of beta, Microsoft has released the C# Version 3.0 Specification (doc format) at their http://msdn.microsoft.com/events/pdc">Professional Developers Conference 2005. http://msdn.microsoft.com/vcsharp/future/">New features include SQL-like and XQuery-like query expressions, implicit (on initialization) typing, lambda expressions and more. The primary focus of the language extensions are encompassed by http://msdn.microsoft.com/netframework/future/linq /">The LINQ Project which aims to bridge the gap between the object-oriented and relational worlds in a simple and type-safe way.
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?
Fixtures is something that JUnit has been ignoring since its inception and thus it is much less appealing than it could be if the test fixture dillemma is ever solved.
Your pizza just the way you ought to have it.
Envy me, I'm programming's MVP!
Hollow words will burn and hollow men will burn.
...especially when spelled with a "z" instead of the proper "s"...
Karma: It's all a bunch of tree-huggin' hippy crap!
Here are a couple of articles explaining why the distinction between tests and unit tests are becoming irrelevant:
a d_id=36502
http://www.theserverside.com/news/thread.tss?thre
http://beust.com/weblog/archives/000319.html
Probably because it was done quite a few times before the parent... by then it starts getting old.
... too cliche.
Hell, before I clicked on the story I thought of "j-j-j-jay unit!"
Deserves "Cliche" mod.
However, I see very little effort put into end-to-end system tests, and that's a shame. The really tricky bugs come from module/process interaction. Furthermore, unlike Unit Tests, system tests reflect the end-user experience. At one place where I worked, the software was just pure crap, but the system testing was thorough and the customers loved the product.
Test 1 2 3 4
CLIQUE, not CLICK. It's a FRENCH WORD. Y'know, the PUSSIES.
Like JTiger has done for ages?
Looks like JUnit4 is adopting most of its ideas from TestNG. This is good, as JUnit feels highly constrained and somewhat crippled compared to TestNG, but why even bother with JUnit4? TestNG can run JUnit tests unaltered, so backwards compatibility isn't really an issue.
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.
http://www.jtiger.org/
Don't annotations use reflection?
-- bearclaw
Interesting you've judged something impossible that thousands of professional developers perform daily.
Using mock objects makes unit testing servlet code pretty easy. Keeping your objects reasonable in size and single purposed in function also simplifies testing. If a servlet is so complex that its hard to test then, that is a sign that it should be broken up and delegate to smaller classes with simpler methods that are easy to test.
JSP's should not have any logic in them, or if they do, it should be trivial. With no logic, there is nothing to test. Move the logic into a servlet (or Action for struts) or for presentation logic, put it in a custom tag. Then you have java that can be validated with the compiler and easily tested.
HttpUnit is very easy to use for testing live web applications but, its reaching beyond the scope of Unit testing and getting into the realm of Acceptance and Integration testing (better tool for qa than a developer).
Stuff in the rights places? Page formatted correctly? Sounds like you want screen capture and image analysis, maybe NASA can help you. JK, really, at some point you just have to look at your pages in the various browsers.
----- If communism is a system where the government owns business, what do you call a system where business owns govern
Some of my professors have developed a tool to help structual testing. JaBUTi (Java Bytecode Unterstanding and Testing) can test java applications and components even it the original java source code isn't available. It is possible to do the structural test through several approachs, like control-flow (all-nodes, all-edges) and data-flow (all-uses, all-potential-uses).
2 131
I have used this tool during some time and it is amazing. It generates graphs of the code you are testing and it can be integrated with junit.
Check this paper for more details: http://portal.acm.org/citation.cfm?id=1072118.107
If I browse to the Junit page and then click on the 'JUnit' link, then the 'back' button will not return me to the 'Junit' page.
Presumably this is because the 'JUnit' page replaces the 'Junit' page in my history (or something like that).
This is not the behavior I would expect, but maybe it's supposed to work this way..?
A testing framework for webapps that runs in the browser. It's both slick and simple.
http://selenium.thoughtworks.com/index.html
Comment removed based on user account deletion
Actually, before JUnit was a thought, this was an idea pushed to support clean, logical, maintainable, and well designed code. If a method is easy to test that might indicate that it has a well defined purpose and a well defined interface, these are good things even if you don't care about testing, agile dev or whatever. Before agile, this just used to be called good code.
Maybe that "bad refactoring" isn't so bad after all. Code shouldn't be refactored to JUnit, it should be refactored to be well structured, clean, and maintainable. If that makes it easier to test, then all the better.
I think when they say refactor to JUnit they really mean that its better to refactor to make the code simpler and cleaner than to not refactor at all.
----- If communism is a system where the government owns business, what do you call a system where business owns govern
Don't know about you, but (not having actually heard the line, and only reading it here) "G-G-G-G-G-G-UNIT" sounds like a poor take on "T-U-R-T-L-E-Power"...
If you are able to read german (or your coworkers are) - Frank Westphal has already written a good comparison for JUnit 3.8 and 4.0 at http://www.frankwestphal.de/JUnit4.0.html. You might want to try this.
It can be quite useful to test GUIs from an automated suite. Checking for the pixel-perfect layout is less common, but if the UI spec says, "the graph is above the table," that's relatively easy to check.
What's more helpful is checking things like, "pressing the Foo button results in the Baz dialog appearing." A good automated suite finds the Foo button by caption/control ID/window class/etc., rather than by pixel location. A better automated suite makes it easy to write your test scripts as abstractions, so instead of:
window.find_button('Foo').push; ui.type_text('42')
you can write your own DSL for testing:
app.set_foo('42')
I tend to lump these kinds of tests into the "functional" rather than "unit" category, but maybe that's just me.
"I call a baby goat a 'goatse.'" -- my non-Internet-savvy 6-year-old stepdaughter
I've done the record/playback thing before, but those tools (good though they are) aren't able to determine intent. What did it mean when I clicked at location (267, 121) and then waited 2417 milliseconds before moving the mouse? And you still have to add pass/fail criteria. Some recording tools simply produce a giant "data dump," in which it's very hard to find where to put your asserts().
One advantage of simply sitting down and writing your GUI test scripts is that you can start from the requirements doc while the app guys are still coding the application you'll be testing.
"I call a baby goat a 'goatse.'" -- my non-Internet-savvy 6-year-old stepdaughter