Friday Aug 10, 2007
Friday Aug 10, 2007
Tuesday May 15, 2007
What is the best way to return status from a test case? This question has been asked more than once during the last week so it deserves a blog post.
Different test frameworks handle test results differently. Alexey has simple a side-to-side comparison of tests formats for JUnit-like tests and JT Harness in his blog. JUnit uses exceptions to signal test failure, JT Harness returns a Status object:
JUnit
public void test() throws AssertionFailedException {
// do something
...
// check result
assertEquals(expectedResult, result);
}
JT Harness
public Status test() {
// do something
...
// check result
return (expectedResult == result)
? Status.passed("OK")
: Status.failed("Unexpected result " + result);
}
The exception-throwing approach appears to be the most straightforward, but it has its drawbacks. While for the simplest unit tests it may make the code easier to read, it quickly gets difficult in more complex cases. And exceptions affect test performance as well.
Here are a few other reasons to use the Status object.
First, use of exception to signal test status violates one of the important API design principles: "never use exceptions for flow control". Exception use is normally restricted to recovery from abnormal conditions such as resource failures or programming errors. A common argument is that test failure is caused by programming error and thus use of an exception is justified, but this is indeed not the case. The one and only reason to write unit tests is to detect bugs. While there is a bug in the underlying code, it should be considered normal flow of control for the test. On the other hand, if the test itself encounters a problem or the underlying code break down unexpectedly, then it is appropriate to throw an exception.
Second, use of an exception artificially limits test outcomes to just "Pass" or "Fail". Use of a return type allows to easily extend test format with additional status types. We found it convenient to have at least yet another status, "Error". "Error" is different from "Fail" as it signals a problem with test initialization or execution; "Fail" means that the test executed successfully and found a bug in the code. Throwing an exception in case of a test initialization problem is justified. In fact, JT Harness defines an exception class (MultiTest.SetupException) just for this purpose.
To summarize, use of a Status object is a cleaner API design. But if you like the brevity of the exception mechanism, it is fine to use as well. Just don't use both at the same time
.
Monday May 14, 2007
Our team has been working hard during the past several months to open source our testing tools: JT Harness and ME Framework. The bits are now available through the cqME project and last week's JavaOne was a great opportunity to spread the word and present our efforts to the wide audience. Until recently our primary focus was conformance testing and we rarely had an opportunity to talk to application developers. This is a brief overview of our last week's activities.
The slogan for this year is "Test More, Port for Less". By conducting better quality and conformance testing and by sharing tests and tools with the community, we are improving the overall implementation quality and reducing fragmentation. Our logo is the Duke of Justice. He resembles Femida, the blindfolded goddess with a scale in one hand and the spec in the other. Enforcing conformance to the spec is what conformance and quality is about.
Roman Zelov, Alexander Glasman and I did a session on Java ME testing (TS-5906) where we covered a range of testing and debugging tools and some of the basic Java ME application and platform testing principles. For more reading on the topic you can refer to Alexey Popov's very detailed blog which covers many of the things we talked about in the session. Roman and Alexander also showed the latest version of the NetBeans plug-in for test development. The plug-in is a work in progress, you can track the status in Alexander's blog.
The detailed introduction to ME Framework and Netbeans plug-in is now available as an online hands-on lab (LAB-9530). A free Sun Developer Network account is needed to get access to it. The latest version of ME Framework and Netbeans plug-in is always available at the cqME project site.
We had a booth on the show floor where we were showing the latest testing tools. Our demo rig was based on a Sun's Opteron box running Linux connected to a Texas Instrument's OMAP730 development board running Sun's CLDC HI stack on Monta Vista Linux. We also used a couple of off-the-shelf devices for test export feature demonstrations.
After talking to the friendly application developers, we now see that we are on the right track with our tools. Application and platform testers have similar needs and are fighting similar problems (device limitations, lack of test automation, implementation bugs, platform fragmentation). A good set of challenges for cqME project to address.
Sunday May 13, 2007
My 10-year-old son is a robot geek and our living room is filled with robots of all shapes and sizes programmed to do different tasks. At this JavaOne I felt like a 10 year old surrounded by different kinds of robots. Java-powered robotics is big at JavaOne this year and I just could not resist looking around.
The robosapien-based RM Media robot from WowWee Robotics is a really impressive toy.
It has a Java ME VM and APIs and can be progammed to do different talks like follow an orange ball. One problem of Java ME platform is the lack of a profile for unconnected devices with limited user input
(no phone-style keypad). Robots like this one or MP3 players would
benefit from an "unconnected MIDP" profile allowing to play
existing games on the LCD screen and write and share new applications.
Simon Ritter and Angela Caicedo showed what the Sun SPOT platform can do by building a virtual reality game application (TS-1780). SunSPOT runs on a 180 MHz 32-bit ARM CPU and supports a CLDC 1.1 VM called Squawk. With hardware and software interfaces to a wide range of sensors, it is a perfect robotics platform.
Autonomous robot navigation have made huge progress the last couple of years. Last JavaOne Paul Perrone showed Tommy, the Java-powered dune buggy he built for the DARPA Grand Challenge. This year he built an autonomous helicopter and is preparing for the DARPA Urban Challenge with his new robotics creation. Both use Java Real-Time System on Solaris 10 at the core of their navigation application (TS-1519).
SONIA is an autonomous underwater explorer developed by the university students in Montreal (TS-1990). Not only did they need to solve the underwater navigation problem, but also keep water from damaging the Java SE-powered brain.
Greg Bollella showed an industrial robot arm built on Java Real-Time System running on standard off-the-shelf Solaris box. Originally designed to hangle croissants at 10G, this is serious stuff, not a toy.
Static and dynamic code analysis tools are advancing. You can now find all sorts of hard-to-find bugs hiding in the code: memory leaks, uninitialized memory, dead code and unused variables.
Alex Kuzmin did a great overview of the today's code analysis tools, both static and dynamic (TS-5711). His talk attracted a lot of interest and had a long Q&A discusion at the end.
William Pugh (the author of the FindBugs tool) did an impressive talk based on his experience with static analysis (TS-2007).
Roman Shaposhnik, talking at an amazing pace, showed a demo of the project called D-Light at James Gosling's keynote. D-Light is a new dynamic performance analysis tool based on D-Trace. It is currently a SunStudio plug-in, but hopefully a NetBeans version will be available soon.
Paul Byrne showed the Wonderland project. It looks like a Java version of Second Life, but it was designed as a collaboration workspace. It re-uses some of the project Looking Glass ideas, but takes them to the next level. This project is currently a concept demo version, but will we one day come to work to a virtual office?
Erik Hellman from Sweden generated a lot of attention with his 3D-gaming session
(TS-3073). Being neither a game developer, nor a 3D API expert, nor an artist,
he put together a really simple Java first-person multi-player shooter game he called
"Duke Bean'em" featuring Duke with guns shooting coffee beans. While the game itself wasn't particularly impressive, it is a good
showcase of a range of open-source Java technologies which demonstrates that 3D
gaming is easier than it is perceived to be.
Saturday May 12, 2007
A few things which I found interesting at the conference this week.
Java EE: Ajax and Web 2.0
Ajax has finally come of age. The were 63 (!) AJAX and Web 2.0 sessions. It is astonishing to see how the 10-year-old technology suddenly becomes mainstream. JavaScript and dynamic HTML are almost as old as the Java platform itself, and dynamic web pages with server-side logic have been used for years, but the potential remained greatly underutilized until recently.
Nowadays we can see all sorts of applications deployed through a browser. Google Maps was only the beginning. Now everyone is using Ajax. Such traditionally thick software as IDE or OS can be run in a browser window offering quick response time and the full range of features complete with sound effects and video streaming (TS-6839).
Ajax is quickly advancing into the mobile space as well (TS-5525).
Will Mobile Ajax revolutionize the mobile application development as we know it?
Java SE: language features
I am always worried when I hear about new Java language features. What greatly attracted me back in 1996 was the simplicity and the relative ease of writing (and, more importantly, reading) the code in Java. Relative to C and C++ that is. Now with its seventh iteration in the making, the language is clearly losing the original simplicity which was so appealing in JDK 1.0.x. Introduction of inner classes back in JDK 1.1 was the first small step and many more features were added since then. Autoboxing, generics and varargs are the few language additions I greatly dislike. Generics, while useful in principle, are simply overly complex (see Ken Arnold's old blog "Generic Considered Harmful"). There are three "evil" features in C++ which made Java language so elegant in comparison: templates, pointers and operator overloading. But they are slowly creeping in!I just love Josh Bloch's Java Puzzlers talks. This year was no exception. Josh and prof. William Pugh put on a great show! (TS-2707) One of this year's puzzlers shows the harmful autoboxing. The following code will unexpectedly print "3.0" because of automatic unboxing, lossy conversion and boxing. Counter-intuitive and potentially dangerous!
Number num = true ? new Integer(3) : new Float(1.5);
System.out.println(num);
In JDK 7 we may see even more language features. Will they be a useful addition to the language? When I found out that Neal Gafter is doing a presentation on closures proposal (TS-2294), I knew I had to check it out. I must admit I had to download the slides after the session in order to understand what is being proposed. The goal is noble: provide an alternative for the hard-to-read syntax of the inner class and template combinations. But the proposed replacement isn't exactly easy to understand either. Here is one of Neal's examples.
Today:
void addListener(final ItemSelectable is) {
is.addItemListener(
new ItemListener() {
public void itemStateChanged(ItemEvent e)
{ doSomething(e, is); }
}
);
}
Same code in the proposed syntax:
void addListener(final ItemSelectable is) {
is.addItemListener(
{ ItemEvent e => doSomething(e, is); }
);
}
The ugly construct is replaced with the one that is hard to understand and, possibly, maintain.
Java ME: interactive TV is finally here!
When I jumped on the Java TV boat back in 2000 (the boat was pJava-powered
),
I did not originally expect the journey to take this long. A few years later I was thinking it may never be over.
But we are finally arriving at the interactive TV age: BD-J players are now in the nearby electronics store.
Unfortunately, it is still too early to claim success. There are more than 200 Blu-ray titles available, but only 6 (!) use BD-J features.
Movie studios say that player compatibility issues and lack of applications are the
primary reasons (TS-5723).
The compatibility issues are troubling. Is this a sign of the "F" word in the TV space? I mean fragmentation, of course.
Friday May 11, 2007
I would like to start my blog with a series of posts about JavaOne 2007 conference in San Francisco. This is my seventh JavaOne, but the conference never starts to disappoint. As usual, this is a great opportunity to meet people from all over the world and learn about new things.
So what is new for 2007?
Java FX is what all the noise is about this year.
There was a lot of confusion about Java FX, Java FX script and
Java FX mobile. What is the relationship between the three?
Java FX is the family of products which will eventually span desktop, TV and mobile devices. It promises to ensure great interactive content, ease of portability and development tools support. Initially, Java FX includes two products: Java FX Script and Java FX Mobile.
Java FX Mobile is based on the mobile phone stack from SavaJe.
Those who attended JavaOne 2006 should remember their orange-colored
handset with AGUI (JSR 209) support.
Java FX Script is the new name of the F3 scripting language by Chris Oliver. The language combines declarative SVG-style interface descriptions with java-like scripting code. With proper tools support it should empower web designer's creativity.
Chris Oliver repeated his Java FX script session (TS-3420) three times, each time it was full. Needless to say, I couldn't get in and missed the demos. Chris has a few demos posted in his blog and they look cool! It took me five attempts to shoot all space invaders .
One complaint: the new JavaOne schedule builder feature wasn't helpful. The overflow rooms last year at least ensured that everyone gets to hear the talk which is full. This year you simply had to be either quick or lucky to get into a popular session. The new Schedule Builder feature did not work as advertised. The card reader at the session door was not synchronized with the database and quite a few folks (including me) could not get in despite going through the pre-registration hassle.
It will be interesting to see how Java FX will transform Java conformance testing. One of the promises of the Java FX technologies is better compatibility and little or no fragmentation. Since there is no way a single binary (or even a binary built from the single source) can run on all devices unmodified, there is a clear need to have a new conformance or compatibility testing program.
Another big announcement is Open JDK. JDK is catching up with Java ME with a widely expected announcement of open source JDK. Mark Reinhold presented the details in his project report (TS-2800). Opening up the JDK source is expected to change the way Java conformance testing is conducted. Patrick Curran writes about this in his blog.
Welcome to my blog!
My name is Mikhail Gorshenev, I am a senior staff engineer at Sun Microsystems in Santa Clara, CA. I am part of the group responsible for Java platform conformance and testing tools.
Some of our open source testing products can be found in the mobile and embedded community on java.net. The umbrella project for testing tools is called cqME which stands for "Compatibility and Quality for the Java ME platform". These tools have been developed by our team over the last ten years and are now available to all Java technology developers and testers.
In this blog I will be writing on various Java specification and conformance topics as well as the new technologies and other interesting things which are happening around me.