Beta
×

Welcome to the Slashdot Beta site -- learn more here. Use the link in the footer or click here to return to the Classic version of Slashdot.

Thank you!

Before you choose to head back to the Classic look of the site, we'd appreciate it if you share your thoughts on the Beta; your feedback is what drives our ongoing development.

Beta is different and we value you taking the time to try it out. Please take a look at the changes we've made in Beta and  learn more about it. Thanks for reading, and for making the site better!

An Early Look at JUnit 4

ScuttleMonkey posted more than 9 years ago | from the still-just-java dept.

Java 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."

cancel ×

147 comments

Sorry! There are no comments related to the filter you selected.

I don't know if I am the only one thinking this... (5, Funny)

TheOtherAgentM (700696) | more than 9 years ago | (#13560861)

Maybe I am the only one that understands this too... J-J-J... J UNIT!

Re:I don't know if I am the only one thinking this (1, Funny)

Anonymous Coward | more than 9 years ago | (#13560986)

You must be that famous rapper's computer-geek brother, 50 GHz...

Re:I don't know if I am the only one thinking this (1)

ViaNRG (892147) | more than 9 years ago | (#13561018)

Yes! When I saw this headline, I so had my fingers crossed for that to be first post! You rule!

Re:I don't know if I am the only one thinking this (0)

Anonymous Coward | more than 9 years ago | (#13561068)

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?

Re:I don't know if I am the only one thinking this (5, Informative)

RUFFyamahaRYDER (887557) | more than 9 years ago | (#13561107)

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.

Re:I don't know if I am the only one thinking this (0)

Anonymous Coward | more than 9 years ago | (#13561495)

CLIQUE, not CLICK. It's a FRENCH WORD. Y'know, the PUSSIES.

Re:I don't know if I am the only one thinking this (1)

Hurricane78 (562437) | more than 9 years ago | (#13561126)

Do you mean:
Marcy: "Say it! Say it!!!"
Jefferson: "J-J-J...Joooob"!
?

Re:I don't know if I am the only one thinking this (2, Interesting)

FooAtWFU (699187) | more than 9 years ago | (#13561180)

I was actually thinking more Moon Unit [wikipedia.org] , myself.

Your not the only one (3, Funny)

sideshow (99249) | more than 9 years ago | (#13561240)

Maybe I am the only one that understands this too... J-J-J... J UNIT!


Envy me, I'm programming's MVP!

Re:Your not the only one (0)

Anonymous Coward | more than 9 years ago | (#13561723)

Dont you mean "a Microsoft MVP"?

Fo' Shizzle! (-1, Redundant)

Anonymous Coward | more than 9 years ago | (#13560863)

J-j-j-j-j-j-JUnit!

Re:Fo' Shizzle! (0)

Anonymous Coward | more than 9 years ago | (#13561024)

Hahaha.. I was gonna say this! C'mon people lighten up a little bit and mark this funny! Naw mean?!

Too bad (5, Interesting)

cached (801963) | more than 9 years ago | (#13560869)

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.

Re:Too bad (1)

AndreiK (908718) | more than 9 years ago | (#13560949)

Eclipse was actually my first experience with pre-defined test cases. And in order to make a GUI test, it's hard to think of the logistics. How exactly is it wrong if a control is one pixel down, or if it doesn't use the right layout. What they really need is an on-the-fly GUI editor. Not a form-editor, but a way to change the code, and reissue a pack in order to change the UI.

Re:Too bad (1)

attonitus (533238) | more than 9 years ago | (#13561373)

And in order to make a GUI test, it's hard to think of the logistics. How exactly is it wrong if a control is one pixel down, or if it doesn't use the right layout

The parent is referring to a GUI to run the tests [informit.com] , not a test to test a GUI.

Re:Too bad (1)

AndreiK (908718) | more than 9 years ago | (#13562222)

Oh, I thought that that was kinda assumed. I'm used to the eclipse panels.

Re:Too bad (-1, Offtopic)

Anonymous Coward | more than 9 years ago | (#13561001)

The only Java app I've ever used was Azureus, and that was only until I found a BitTorrent client that wasn't written in Java and didn't suck up vast amounts of RAM and processor time.

How about covering some open source lanugages instead of Sun's proprietary bloat-fest?

Re:Too bad (0)

Anonymous Coward | more than 9 years ago | (#13561118)

Java is open source. It's just not under the communist GPL.

Re:Too bad (0)

Anonymous Coward | more than 9 years ago | (#13561421)

Java is open source.

Just like Microsoft's "Shared Source" is open source too!

Re:Too bad (1)

rewt66 (738525) | more than 9 years ago | (#13561805)

And I sure don't understand why. I mean, given the GUI test runner from JUnit 3, and the text test runner from JUnit 4, is it really that hard to produce a GUI test runner for JUnit 4?

This is annoying enough that somebody's going to just hack one out, unless there's some technical reason why it can't be done that's eluded me...

RE: Too bad (2, Informative)

Slurm (147172) | more than 9 years ago | (#13561870)

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.


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] .

JUnit4 (-1, Offtopic)

Anonymous Coward | more than 9 years ago | (#13560870)

J-J-J-J-Jay UNIT.

Sorry, I just had to.

Re:JUnit4 (0, Offtopic)

Dr Reducto (665121) | more than 9 years ago | (#13560950)

How is the parent off topic?

It at least deserves a "funny" mod

Re:JUnit4 (0)

Anonymous Coward | more than 9 years ago | (#13561372)

Probably because it was done quite a few times before the parent... by then it starts getting old.

Hell, before I clicked on the story I thought of "j-j-j-jay unit!" ... too cliche.

Deserves "Cliche" mod.

Testing (1)

AndreiK (908718) | more than 9 years ago | (#13560881)

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.

Re:Testing (2, Informative)

ashridah (72567) | more than 9 years ago | (#13561071)

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

Re:Testing (2, Insightful)

MSBob (307239) | more than 9 years ago | (#13561533)

My idea would be to tackle the mocking scenario by intercepting methods with AOP (AspectJ most likely) and subsituting mocked return values. This would at least make it possible to unit test legacy code without major refactoring and avoid some really questionable design decisions that junit sometimes forces you into.

Re:Testing (3, Insightful)

LnxAddct (679316) | more than 9 years ago | (#13561920)

At any major development place, *everything* is unit tested. Code coverage (how many lines of code are actually covered by the tests) is huge and should usually be above 70%. Unit tests aren't to make sure that your code is working correctly right now, unit tests are so that in 5 years when you change one class out of 6000 interdependant classes you can just run "ant test" and it goes back, runs all your tests and makes sure they still pass as they did when you first wrote it 5 years prior. Without unit testing, modifying any major, complex piece of software would be hopeless. You can unit test anything, including apps that require databases. You simply "mock out" the database using JMock and it stands in place for it like a fake database almost. The development I do is heavily dependant on Oracle and Java and JUnit/JMock are critical to the project's success. It is a common practice in open source now too as was seen by the recent release of Gallery 2.0 which is largely unit tested.
Regards,
Steve

Look around you (2)

Eunuch (844280) | more than 9 years ago | (#13560899)

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.

Where was the headline when NUnit was released? (1, Insightful)

soconnor99 (83952) | more than 9 years ago | (#13560907)

That supported attributed programming years ago? Oh I know, NUnit is a port^H^H^H^Hripoff of JUnit so it doesn't count.

Re:Where was the headline when NUnit was released? (3, Informative)

CadmannWeyland (609987) | more than 9 years ago | (#13561027)

Actually, there are a number of xUnit implementations out there. JUnit is just one of many for many languages. NUnit is by no means a rip off of JUnit than JUnit is of pyUnit, or cppUnit, etc.

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:Where was the headline when NUnit was released? (1)

Kentamanos (320208) | more than 9 years ago | (#13561367)

I think his point is more specifically about marking your code with .NET "attributes" to specify the method is a test etc.

In other words, Java added a new feature to the language in Java 5 (called "annotation") which was something that .NET had (called "attributes") and now the new JUnit is allowing you to mark your methods specifically as tests to be run (like NUnit has for quite some time).

Re:Where was the headline when NUnit was released? (1)

CadmannWeyland (609987) | more than 9 years ago | (#13561542)

I understood his point, and am aware that NUnit uses attributes, and think its cool if the JUnit guys want to add it. Of course, a valid point here is that the Java stuff gets attention, and perhaps the .Net stuff does not....

I was addressing the fact that the xUnit community (at least the various folks that like/use/support the xUnit-style implementations, don't look at NUnit being a "rip-off" of JUnit. I think its great that NUnit initially learned from JUnit (and they from the smalltalk, c++ versions, etc.), and that in turn JUnit is learning from NUnit.

IMHO (and part of my point) is that the xUnit framework stuff has always been multi-language and is outside the whole religious java vs .net vs whatever arguments. It's way cool to me as a test-first developer that I can probably find an xUnit implementation for just about any language I run into.

Cadmann

Re:Where was the headline when NUnit was released? (1)

Kentamanos (320208) | more than 9 years ago | (#13561625)

No problem. I'm sure his comment was definitely a backlash against the people who spell Microsoft with a "$" :). He was just trying to show something that went the other way in the typical "rip off" arguments (both from a language and xUnit standpoint ).

I try to stay neutral on the "X" ripped off "Y" arguments. It turns out that a lot of the time when people "reinvent the wheel", they end up doing a slightly better job since they have the benefit of hindsight.

If you do any .NET stuff in Visual Studio by the way, be sure you've looked at http://www.testdriven.net/ [testdriven.net] . It's a very sweet way to do unit tests with NUnit (and other test suites) within Visual Studio. It allows you to right click within a test method and run it as a test etc. Very handy...

Re:Where was the headline when NUnit was released? (2, Informative)

PostItNote (630567) | more than 9 years ago | (#13561730)

JUnit was actually the first - it was written back when people were still figuring out to call it "unit testing" as distinct from functional testing, and it was certainly the first widely used framework that supported unit testing.

In that sense, all the other xUnit stuff is decidedly a descendant of JUnit.

Re:Where was the headline when NUnit was released? (3, Informative)

Curt Cox (199406) | more than 9 years ago | (#13561861)

Almost. The Smalltalk version (SUnit) was the original which inspired JUnit. It wasn't the watershed that JUnit was due to the relative popularity of the languages.

Just when I'd almost gotten comfortable (2, Funny)

Elrac (314784) | more than 9 years ago | (#13560912)

...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.

Try TestRe:Just when I'd almost gotten comfortable (1)

JSR $FDED (410612) | more than 9 years ago | (#13561154)

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/ [testng.org]

Java 5, JUnit4 (3, Interesting)

ReformedExCon (897248) | more than 9 years ago | (#13560925)

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.

Re:Java 5, JUnit4 (2, Interesting)

Surt (22457) | more than 9 years ago | (#13561087)

The @Test annotation allows you to drop the test from your test method name. This is a minor help it:

a) reduces the method name length slightly, there are various tools that aren't up to handling super long method names.

b) more importantly, can simplify your naming conventions

way way way more important is that
extends TestCase

is no longer necessary, which since Java is single inhertiance model now means you can extend something else with your test classes. As one significant example, think about writing tests that extend the tested class, and how that helps to better maintain the protection mechanism.

No doubt about it, this will be a big step forward in JUnits power.

Re:Java 5, JUnit4 (2, Informative)

iabervon (1971) | more than 9 years ago | (#13561449)

I haven't looked at the details yet, but I think you're supposed to be able to affect compilation using annotations, and you can certainly have tools post-process class files using annotations. What that means is that you can have a "production build" which strips out everything annotated with the JUnit annotations, and have your tests actually in the class they're testing, but have them not end up in the final application. Then it's easy to find the tests for a class (they're in the same class) and the tests can even peek at private fields, which is really nice, because sometimes you don't want subclasses messing with some of the fields you want to test.

JUnit4 ? Goddess ? (2, Funny)

karvind (833059) | more than 9 years ago | (#13560931)

But wikipedia says Junit was a minor goddess [wikipedia.org] .

Just kidding, JUnit [wikipedia.org] , one with capital U.

Re:JUnit4 ? Goddess ? (1)

Joey Patterson (547891) | more than 9 years ago | (#13561058)

wikipedia says Junit was a minor goddess.

Slashdotters have a goddess now? Cool! Can we get an early look at her, too?

Bug or feature in firefox? (0)

Anonymous Coward | more than 9 years ago | (#13562486)

If I browse to the Junit page [wikipedia.org] 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..?

ive noticed.. (-1, Offtopic)

Anonymous Coward | more than 9 years ago | (#13560932)

scuttlemonkey's stories are all so boring.

The Holy Grail (2, Interesting)

Catamaran (106796) | more than 9 years ago | (#13560943)

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 [ptc.com] has this capability. Are there other applications that can do that?

Re:The Holy Grail (3, Funny)

KenSeymour (81018) | more than 9 years ago | (#13561394)

The system I am looking for would use microphones to record all the conversations regarding requirements, resolve them into structured documents, then generate unit tests for all the requirements.

It would have to use microphones because, in my experience, you don't get a written requirements spec. Or if you do, customers don't feel constrained by it.

It would also have to raise a red flag when the customer contradicts themselves in the same sentence or paragraph.

But all kidding aside, JUnit is cool.
For intricate portions of my code I write tests that represent specific scenarios and run regression tests whenever I have finished implementing the new rule of the day.

Re:The Holy Grail (1)

Catamaran (106796) | more than 9 years ago | (#13561520)

Hey, I think we work for the same company!

Yes, JUnit is nice. All of the XUnits are nice. They address one of the major problems in software development, which is the constant divergence of tests and code. But there are other ways to address that problem. The method that I subscribe to is this: don't allow developers to check in code until it passes all existing tests. It takes come descipline, but it works.

By the way don't forget to patent that microphone idea.

Re:The Holy Grail (0)

Anonymous Coward | more than 9 years ago | (#13562006)

I think JUnit is trying to serve a different need. For instance, if this artcle was a review of Pro/Engineer I would wonder how it might support test driven development.

Maybe doing TDD with Pro/Engineer should be called Catch 22 Development.

Re:The Holy Grail (4, Funny)

willCode4Beer.com (783783) | more than 9 years ago | (#13562267)

I say the holy grail is combining unit testing with genetic algorithms.
Then you just write the tests and let the code "evolve" until it passes them. Meanwhile, you get to sit around and drink beer.

More on Elliotte (4, Informative)

tcopeland (32225) | more than 9 years ago | (#13560946)

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 [ibiblio.org] and has written a slew of excellent books.

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:More on Elliotte (0)

Anonymous Coward | more than 9 years ago | (#13561352)

I had the opportunity of learning java from this guy. He was absolutely horrible. He gave everybody A's, though a few people missed his final. He also thinks he's very funny - he'll laugh at his own jokes, while everyone gets kinda.. uncomfortable.

Could we cut down at manager speak here (1, Insightful)

melted (227442) | more than 9 years ago | (#13560953)

"Utilize" would be "use" if you were speaking plain English. And no, using the word "utilize" doesn't make you seem any smarter.

Re:Could we cut down at manager speak here (3, Funny)

iggymanz (596061) | more than 9 years ago | (#13561041)

To recap in manager-speak, you're saying the utilization of utilize nets suboptimal perceptual leadership utility?

Re:Could we cut down at manager speak here (1)

melted (227442) | more than 9 years ago | (#13561116)

>> To recap in manager-speak, you're saying the utilization of utilize nets suboptimal perceptual leadership utility?

No, it simply doesn't leverage any paradigm leading to go-to market, customer focused synergies.

Re:Could we cut down at manager speak here (1)

strcmp (908668) | more than 9 years ago | (#13561265)

Usage Note: A number of critics have remarked that utilize is an unnecessary substitute for use. It is true that many occurrences of utilize could be replaced by use with no loss to anything but pretentiousness, for example, in sentences such as They utilized questionable methods in their analysis or We hope that many commuters will continue to utilize mass transit after the bridge has reopened. But utilize can mean "to find a profitable or practical use for." Thus the sentence The teachers were unable to use the new computers might mean only that the teachers were unable to operate the computers, whereas The teachers were unable to utilize the new computers suggests that the teachers could not find ways to employ the computers in instruction.

From dictionary.com

Americana (1)

Trejkaz (615352) | more than 9 years ago | (#13561304)

...especially when spelled with a "z" instead of the proper "s"...

Re:Americana (0)

Anonymous Coward | more than 9 years ago | (#13561994)

Not a problem according to the Oxford English Dictionary.

G- no J-Unit (0, Redundant)

qedigital (545151) | more than 9 years ago | (#13561021)

j-j-j-jaay-uuunit!

sorry, it's the first thing that sprang to mind upon reading the headline

Re:G- no J-Unit (-1, Troll)

Anonymous Coward | more than 9 years ago | (#13561400)

SCO acquires a new business partner - GNAA

SCO acquires a new business partner - GNAA

Darl here, with another fine Fr1st P0st. After all -- SCO did
everything first, and the rest of the responses to this story will owe
their heritage to a foundation built on SCO's staff of talented programmers.



You may be wondering why SCO salesmen are not answering your numerous calls
while you try to order more SCO licenses. Well, we aren't answering the phones
because we're too busy celebrating our newest business partner. Rather than
explaining it myself, I'll let our formal press release do the talking. Take it
away, Mr. Reuters...



LINDON, Utah, Sept. 8/PRNewswire - FirstCall/ -- The SCO Group,
Inc.
(Nasdaq: http://finance.yahoo.com/q/bc?s=SCOX&t=5y&c= [slashdot.org] "> SCOX
- http://finance.yahoo.com/q/h?s=SCOX [slashdot.org] ">News), the owner and
licensor of the core UNIX operating system source code, today announced its
second Fortune 500 clent for the SCO Linux IP license, the GNAA (Nasdaq: http://finance.yahoo.com/q/bc?s=RHAT&t=5y&c= [slashdot.org] "> RHAT -
http://finance.yahoo.com/q/h?s=RHAT [slashdot.org] ">News), developer of fine
Slashdot trolls on irc.efnet.net #GNAA, also well-known for
revolutionizing small business development with its "Step 2: ??????" profit
model. The availability of the SCO Intellectual Property License for Linux
affords Linux deployments to come into compliance with international law for
the use of all 2.4 and future kernels. The run-time license permits the use of
SCO's intellectual property, in binary form only, as contained in Linux
distributions.



By purchasing a SCO Intellectual Property License, customers avoid
infringement of SCO's intellectual property rights in Linux 2.4 and Linux 2.5
kernels and assure Darl financial security for the purchase of his second home.
Because the SCO license authorizes run-time use only, customers also comply
with the General Public License, under which Linux is distributed. Source may
still be distributed under the terms of the GPL, however source distributors
are held accountable for all violation of SCO's IP. Indemnification is provided
for customers of runtime clients only. Read that twice, dirty hippy. You're not
in the clear yet.



GNAA spokesperson penisbird said of the licensure, "coming into compliance
affords us a new competitive advantage with the other Slashdot authors. By
being in the right, we can thumb down our noses at not only the Windows users
and the BSD-thieving Mac Users, but also the unwashed Linux hippies running
stolen code on their parents' PCs." VP of anus enlargement goat-see added,
"fr1st p0st? damn i miss. how do i next story?"



Mr. Darl McBride concurred with GNAA's analysis, adding "We soon hope to
convince additional clients such as Trollklore and Cabal of Logged In Trolls of
the benefits of licensing SCO's valuable IP. Also, I <3 GNAA bunny. (@.@)"
JesuitX clarified the nature of the SCO and GNAA alliance, adding "We're more
than just a licensing client. We're also going to be helping to bring these
other potential licensors into compliance. We can break them in little by
little as paying sublicensors. The alternative is pretty horrible. Our lawyers
can take a reticent client from virgin to hello.jpg [http://rd.yahoo.com/*http%3A%2F/goatse.cx?busines s=news/083103&sid=34 [slashdot.org] ">figure
2] in under an hour, and believe me -- it is not pleasant."



Commander Taco was unavailable for comment, however Cowboy Kneel was said to
ask for a print of [figure 2] for his basement apartment. Simoniker remained
British and unable to spell "color," while Timothy responded by posting the
same story six times, and Hemos reposted a seventh time, the submission
differing only from his application of that damned Einstein icon.



About GNAA:

GNAA (GAY NIGGER ASSOCIATION OF AMERICA) is the first
organization which gathers GAY NIGGERS from all over America and abroad for one
common goal - being GAY NIGGERS.

Are you http://klerck.org/spin.gif [slashdot.org] "> GAY ?

Are you a http://www.mugshots.org/sports/oj-simpson.jpg [slashdot.org] "> NIGGER ?

Are you a http://www.gay-sex-access.com/gay-black-sex.jpg [slashdot.org] "> GAY NIGGER ?

If you answered "Yes" to all of the above questions, then GNAA (GAY NIGGER
ASSOCIATION OF AMERICA
) might be exactly what you've been looking for!

Join GNAA (GAY NIGGER ASSOCIATION OF AMERICA) today, and enjoy
all the benefits of being a full-time GNAA member.

GNAA (GAY NIGGER ASSOCIATION OF AMERICA) is the fastest-growing
GAY NIGGER community with THOUSANDS of members all over United States of
America and the World! You, too, can be a part of GNAA if you join
today!

Why not? It's quick and easy - only 3 simple steps!


Talk to one of the ops or any of the other members in the channel to sign up
today
! Upon submitting your application, you will be required to submit
links to your successful First Post, and you will be tested on
your knowledge of GAYNIGGERS FROM OUTER SPACE.

If you are having trouble locating #GNAA, the official GAY NIGGER
ASSOCIATION OF AMERICA
irc channel, you might be on a wrong irc network.
The correct network is NiggerNET, and you can connect to
irc.gnaa.us as our official server. Follow this link [slashdot.org] if you are using an irc client such as mIRC.

If you have mod points and would like to support GNAA, please moderate this post up.

Copyright (c) 2003-2004 http://www.gnaa.us/ [slashdot.org] ">Gay Nigger Association of America

JUnit and the people who don't use it... (2, Insightful)

MosesJones (55544) | more than 9 years ago | (#13561048)


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.

Re:JUnit and the people who don't use it... (3, Insightful)

kevin_conaway (585204) | more than 9 years ago | (#13561122)

Unit testing for web apps has a long way to go. Normally, writing junit tests is less then or equal to the amount of work in writing the actual code. Writing unit tests for web applications is vastly more complex and time consuming.

Re:JUnit and the people who don't use it... (0, Troll)

MosesJones (55544) | more than 9 years ago | (#13561174)

Welcome to the unprofessional developer Island... population you.

Normally, writing junit tests is less then or equal to the amount of work in writing the actual code

Where as fixing the bugs as a result of a lack of unit testing doesn't take any effort at all.

You muppet.

Re:JUnit and the people who don't use it... (1)

kevin_conaway (585204) | more than 9 years ago | (#13561235)

Grr. I'm not arguing against them in general. We write them for our backend components. Writing them for a GUI or Web module however takes more time than its worth.

Re:JUnit and the people who don't use it... (1)

digerata (516939) | more than 9 years ago | (#13561281)

Your personal comments are out of line and show your immaturity in the software world.

Fixing bugs as a result of a lack of unit testing does take effort. In some cases, bugs make it to production. But in the case of enterprise scale web applications backed by complex databases, Unit Testing takes 2 - 3 times as much work. It slows down development as you are not only updating test code along with your application code, but you are also updating your schema *and* your test data.

Don't think I'm not for Unit Testing. Believe me, I'm an advocate of it here at work. In any situation we can (typically our libraries), we have unit tests with JUnit. But it just does not work when:

- you have complex web GUI that cannot be emulated with test frame work.
- you have complex database schema backing your application.

Re:JUnit and the people who don't use it... (0)

Anonymous Coward | more than 9 years ago | (#13561335)

You're the muppet, apparently you can't even read simple English.

Re:JUnit and the people who don't use it... (2, Insightful)

Tim C (15259) | more than 9 years ago | (#13561435)

The point, dummy, is that it's next to impossible to use Junit to test servlet code, and downright impossible* to use it to test JSPs. Unfortunately, other than things like HTTPUnit (which last time I looked was almost useless) and WinRunner (which costs and only runs on Windows) there isn't a lot available for proper interface testing of web pages. Not just screen scraping, "do I get the expected data?", but proper "all of the formatting is correct, images in the right place, etc" testing.

(* No, nothing is impossible - but using junit to test JSPs is the next best thing, especially when you actually have a deadline to meet)

JUnit is a woderful tool for testing plain old Java objects, but is utterly unsuitable for end to end testing in a web (or other GUI) environment.

mock objects (2, Interesting)

willCode4Beer.com (783783) | more than 9 years ago | (#13562028)

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.

I'm opposed to Unit Testing (2, Insightful)

Catamaran (106796) | more than 9 years ago | (#13561432)

Well, not really, but my experience has been quite different. I don't know anyone who doesn't at least pay lip service to the concept of Unit Testing. In fact most developers I know follow a pattern of code a little, test a little.

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.

Re:I'm opposed to Unit Testing (1)

willCode4Beer.com (783783) | more than 9 years ago | (#13561773)

software was just pure crap
the customers loved the product

You call a thoroughly tested piece of software loved by its customers crap?
Do you work at Microsoft where buggy, hated sofware is called high quality?

Not yet with Java5 (1)

roman_mir (125474) | more than 9 years ago | (#13561052)

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.

Re:Not yet with Java5 (0)

Anonymous Coward | more than 9 years ago | (#13561911)

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 ;)
Annotations are far from being a pre-processor.

"The metadata feature in J2SE 5.0 provides the ability to associate additional data alongside Java classes, interfaces, methods, and fields. This additional data, or annotation, can be read by the javac compiler or other tools, and depending on configuration can also be stored in the class file and can be discovered at runtime using the Java reflection API."

Read more here [sun.com]

Re:Not yet with Java5 (1)

tonejava (772709) | more than 9 years ago | (#13561917)

I've looked at Java 5 and I am really pushing for it to be adopted in my workplace. The new programming semantics make the code more readble and faster to program - the for loop for example, no more java.util.Iterator! Annotations are kind of handy but when it comes to the JUnit 4 and TestNG methodology of testing it's embedding the tests in your code. The original idea for subclassing was so you had that separation of test code and production code - why double your production code with the test cases? No doubt Java 6 is out next February and Java 7 the following february so how much longer can Java 1.4 be considered mainstram? NOTE I'm not saying it is not now as that is certainly the case.

Maybe, but it doesn't work with databases... (2, Informative)

digerata (516939) | more than 9 years ago | (#13561099)

Many feel that this is one of the most important third-party Java libraries ever developed.

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:Maybe, but it doesn't work with databases... (1)

badmammajamma (171260) | more than 9 years ago | (#13561147)

DBUnit didn't scale to the enterprise level? It's a fuggin test tool. What scaleability are you talking about.

As for the XML...I have mixed feelings about it but it makes sense when you think it through. In any event, DBUnit will export the XML from your db for you.

Re:Maybe, but it doesn't work with databases... (4, Interesting)

prisonercx (40652) | more than 9 years ago | (#13561230)

I understand your frustration. One workaround I've seen uses the Spring framework's annoyingly-named AbstractTransactionalDataSourceSpringContextTests [springframework.org] . Your test classes subclass that monstrosity, and after each test method is run the transaction is rolled back to avoid mucking up the DB for subsequent tests. When you test DAOs, you have to have a custom method for inserting test data before or during each test. Once you get above the data access layer, you just use your now-tested DAOs.

It requires you to define the way you get your database connection through Spring, but that abstraction is necessary for unit testing DB-driven apps anyway. On one of my projects, I have one set of bean descriptions for unit testing which connects right to the DB and one set of beans for when the app is running in a Tomcat container. It's not a perfect method, that's for sure, but it allows me to unit test my code pretty painlessly once it's set up.

Re:Maybe, but it doesn't work with databases... (1)

Abcd1234 (188840) | more than 9 years ago | (#13562361)

"Once you get above the data access layer, you just use your now-tested DAOs."

Huh? When you get above the data access layer, you create a mock DAO that implements the interface and use that to test your business objects. Christ, that's the whole damned reason why Spring is such an excellent unit test enabler: you can easily mock out interfaces and test components in isolation. Which is the very definition of unit test (as opposed to integration or system-level test).

Re:Maybe, but it doesn't work with databases... (1)

Trejkaz (615352) | more than 9 years ago | (#13561346)

It's not so bad. The application I'm working on at work is backed by a database, and all we do is keep around a bunch of precooked databases, take a copy of the database (copying the files is enough) and run all the tests on that.

One of the ways you can cheat the system is if you have the capability to control the transactions from the unit tests, you can set a save point before the unit test and roll back to it after the unit test, so that the next tests don't get trash data from the previous ones.

And yeah, we don't touch DBUnit... that thing is satanic.

Re:Maybe, but it doesn't work with databases... (0)

Anonymous Coward | more than 9 years ago | (#13561684)

The whole point of a UNIT test is that you only test one UNIT at a time. You're not testing code+database, you're JUST testing the code. Replace your database interface and a dummy object that supports the exact same interface but only gives the answers you need for the test.

Your code is well-factored so that you can replace key objects like a Database with other implementations...right?

Re:Maybe, but it doesn't work with databases... (1)

LnxAddct (679316) | more than 9 years ago | (#13561947)

Why can't you mock out the database?
Regards,
Steve

Re:Maybe, but it doesn't work with databases... (1)

dwilson837 (914931) | more than 9 years ago | (#13562037)

If you can, switch to JDO. Among all the other great benefits, DB related testing goes down in both volume and difficulty. After 2 years with JDO, I can't imagine not using it. I recommend http://www.solarmetric.com/ [solarmetric.com]

Re:Maybe, but it doesn't work with databases... (0)

Anonymous Coward | more than 9 years ago | (#13562096)

JUnit works great, can easily be extended and enhanced to suit your local need. I vaguely remember reading somewhere that Kent Beck did not really want to distribute it in binary form, he wanted to distribute the source and have people just use it as a start point for building their own test frameworks. Is my memory close to the mark?

One measure of good code is that it is testable. If you choose a technology/design/architecture that is not testable then that is your choice. However, don't blame the testing tools for your design decisions.

Anyway, JUnit is great for unit testing .... unless you really don't want to do unit testing and are more interested in looking for excuses not solutions.

Web / GUI (1)

kevin_conaway (585204) | more than 9 years ago | (#13561198)

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?

Re:Web / GUI (1)

Trejkaz (615352) | more than 9 years ago | (#13561366)

We usually design the entire GUI to be properly separated into model/view in the first place, so that we can thoroughly test the model to the point where we know that no matter what bug might exist in the UI itself, the user won't be able to find it. ;-)

What you're looking for for web stuff is probably HttpUnit. There is an equivalent for Swing apps too, but we've tried it and it really took more time (10 times more) to write the tests than to write the code, so we decided against it.

Re:Web / GUI (2, Informative)

KenSeymour (81018) | more than 9 years ago | (#13561491)

Someone once referred me to Cactus, [apache.org] which is an extension of JUnit.

It only helps you for web apps, though.

Re:Web / GUI (1)

ezweave (584517) | more than 9 years ago | (#13561516)

I have used JUnitEE [junitee.org] for some time. It provides a Servlet runtime for your tests/test suites. It makes JUnit alot easier to deal with for some type of testing.

Of course, if you are smart you will write an Ant script that will fire off tests for you (using conventional JUnit)... but that only works for some things and it depends on how well you write your tests.

Re:Web / GUI (1)

Falconne (792743) | more than 9 years ago | (#13561731)

Try Selenium: http://selenium.thoughtworks.com/index.html [thoughtworks.com]

It's better than HTTPUnit as it runs your app in a browser, rather than trying to emulate a HTTP client and failing to support complex JavaScript.

Supports Fit Test scripts.

Re:Web / GUI (0)

Anonymous Coward | more than 9 years ago | (#13562087)

Do you mean how to write unit tests for GUIs? Or do you mean any programmer tests with JUnit? If you mean the latter, I recommend http://abbot.sf.net/ [sf.net] . As far as I know, unit tests for GUIs are not really feasible. Be sure to have as few code as possible in your GUI layer so you can unit test most of your code (and thus avoid to spend much time in your debugger) and do some acceptance/functional testing with a bot like Abbot to feel comfortable with your GUI code.

Super off-topic (1, Informative)

Anonymous Coward | more than 9 years ago | (#13561204)

Can anyone tell me why this story was rejected:

With Visual Studio .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 [anonymouse.org] ">Professional Developers Conference 2005. http://msdn.microsoft.com/vcsharp/future/ [anonymouse.org] ">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 / [anonymouse.org] ">The LINQ Project which aims to bridge the gap between the object-oriented and relational worlds in a simple and type-safe way.

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:Super off-topic (0)

Anonymous Coward | more than 9 years ago | (#13561219)

You're new here, aren't you?

Sit back, have some Kool-Aid, and watch the pretty blinkinlights for a little while, and it will all become clear....

Useless (2, Interesting)

MSBob (307239) | more than 9 years ago | (#13561224)

The change that all unit test frameworks need is to address the issue of creating complex setups that your code typically relies upon to execute its tasks properly. Whether it be through mock objects or proper environment setup, at the moment it is the biggest PITA and many, many developers question whether the effort of maintaining those setup fixtures is worth the benefit of unit testing.

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.

Re:Useless (1)

willCode4Beer.com (783783) | more than 9 years ago | (#13562128)

The requirement of complex setup for tests suggests one of two things:
Your tests may be beyond the scope of "unit" tests. Integration tests maybe?
The code needs to be broken up into simpler units that are easier to test individually.

Regarding the first case, how would you validate the code without testing?
The second is just some code that requires refactoring.

Unit tests are becoming irrelevant (1)

JSR $FDED (410612) | more than 9 years ago | (#13561311)

Here are a couple of articles explaining why the distinction between tests and unit tests are becoming irrelevant:

http://www.theserverside.com/news/thread.tss?threa d_id=36502 [theserverside.com]
http://beust.com/weblog/archives/000319.html [beust.com]

Re:Unit tests are becoming irrelevant (1)

CryBaby (679336) | more than 9 years ago | (#13562039)

You linked to two opposing articles. One that tries to narrowly define unit testing and then Cedric's critique of that article. I'm interested, what exactly did you mean? Do you just think that the *term* "unit test" is becoming irrelevant or the actual act of writing unit tests?

been there, done that (2, Informative)

vidnet (580068) | more than 9 years ago | (#13561823)

simplify testing by exploiting Java 5's annotation feature

Like JTiger [jtiger.org] has done for ages?

Why not just use TestNG? (4, Informative)

CryBaby (679336) | more than 9 years ago | (#13561826)

Looks like JUnit4 is adopting most of its ideas from TestNG [testng.org] . 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 [theserverside.com] , 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.

JTiger is better (0)

Anonymous Coward | more than 9 years ago | (#13561838)

Annotations use reflection, yes? (1)

bearclaw (217359) | more than 9 years ago | (#13561860)

Don't annotations use reflection?

Re:Annotations use reflection, yes? (0)

Anonymous Coward | more than 9 years ago | (#13562016)

Although your question leaves room for... well, any answer I think I guess you mean something like "I have to use reflection to retrieve an annotation of a method/class/..., right?" or "Do I have to use reflection to find all methods with this and that annotation?"

The answer is "yes". As well as I have to use reflection to find all methods beginning with "test" in a class extending TestCase. So, no real difference between JUnit 3 and 4 in that respect.

Check this paper (4, Interesting)

gustgr (695173) | more than 9 years ago | (#13562186)

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).

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.1072 131 [acm.org]
Load More Comments
Slashdot Login

Need an Account?

Forgot your password?