Saturday, November 28, 2015

(Im)Proper way to end an iOS app . . .

I am very new to Swift and iOS programming in general, and I had a situation where I wanted to throw an exception to fail an app in an unacceptable situation, and all I knew to do was to call exit(1) in plain old C-fashion.  I put that in my code like on the first day, and I forgot about it.  Since then I have had a lot of bizarre problems with XCode like not running my tests and just logging weird errors like "Failed to bootstrap" and other things.  I finally figured out that was what was causing the errors, and instead I could use:


    fatalError(@autoclosure message: () -> String = default, file: StaticString = default, line: UInt = default)

E.G.

   fatalError("You did something dumb.");

and it accomplishes the same thing (tells me I have done something stupid), but now the debugger stops on that line of code so I remember exactly what I have done.

exit(int), don't use it.

By the way, this is something that only a developer could do, clearly this would not be the way to handle an unexpected user condition.

Tuesday, November 24, 2015

Preach it, brother.

I came across this post today.


I especially like this:  “There is a fundamental difference between the few developers that will become highly skilled and all the other copy and paste developers. The former know they lack knowledge and take the time to grow it. The latter never bother, they go on with what little they know, trying to hack together something and calling it a day.”

Life can be frustrating as a dig-in-and-find-out-how-it-works developer, but I have always admired someone who will dig into something, endure the frustration and "What were they thinking???!?" moments, and come out on the other side with an actual understanding of how something works.

Wednesday, November 4, 2015

Swift Protocol-Oriented programming

Apple makes a big deal about Protocols in swift and how they are better than anything else ever.  I found it quite irritating that nowhere in their explanation of what makes them so great did they mention that a protocol is eerily similar to an interface in Java.  Moving from a C++ background to Java, I was completely baffled why you would use an interface rather than an abstract class.  That question was answered back in 1997 when I started designing applications and APIs using interfaces first.  Nowadays, moving into swift, protocols certainly have features that interfaces do not - such as extensions and conditional conformance - but really - this is not something they just pulled out of nowhere.  I wish they didn't have to act like every thing they do is new and unprecedented.

It would be so much more honest for them to come out and say, "In designing a new language, we looked at what works in Java, Lisp, Python, (gasp) Perl, Haskell, Go, JavaScript - the needs of iOS and the environment apps find themselves in - and created a best-of-breed language."

Swift 2.0, Reference and Value Types, and Unintended Sharing.

I have recently begun learning swift 2.0, because I would like to build an iOS app and I really don't want to have to learn Objective-C.  I am trying to learn it the right way, which means understanding how the language works and not just mutating examples to learn by accident.

I have been reading a lot about structs and classes, and the difference between value types and reference types.  In short, classes pass around object references and structs make copies whenever you pass them around.  I visualize it in old-school terms:  Classes use pointers, but with structs the variable IS the data.

This seems pretty simple - especially if you are comfortable with object languages.  I have watched a few Apple videos, though, and they make it sound revolutionary.  This one in particular goes on about unintended sharing - I pass a handle to the same object into two different contexts where they are expected to be independent.  Change one, impact the other, etc.  His illustrative example was "I created a thermostat object, assigned it to my house.  Then I set the thermostat in my oven to 450, and my house caught on fire!"  Paraphrase.  Gag - what a juvenile way to introduce a language feature.  They could have at least used a real-world scenario they came across implementing their standard libraries that made this feature such a deal-maker.

This seems to me to be very valuable to a college student, or someone learning an object language coming from C, but really, is this that big of a deal?  I can honestly say that I haven't had a bug of this type in my code, that I have detected of course - for decades.  On the other hand, I just spent an agonizing couple of days trying to figure out why extremely routine code did not work.  Take this example:

var map = [String: [String: String]]();
var subMap = [String: String]();
map["map"] = subMap;

subMap["1"] = "2";

For those who don't know swift, this means create a map which can hold maps of string value/pairs.  Next, create a string value/pair map, and assign it to the key "map" in the top-level map.  Finally, assign the key/value entry "1" -> "2" into the sub map.  The expectation being that it will be reflected in the top-level map as well.  This is pretty standard in Java - I do it a lot so I can factor code which handles the sub trees into external code.  In this case, it doesn't work.  Because collections in swift are structs - I.E., value types - the assignment on the third line makes a copy which is unaffected by the assignment on line 4.  I came up with this working code after much hair-pulling:

var map: Dictionary = [String: [String: String]]();
map["map"]!["1"] = "2";

And only later uncovered the reason that I explained before.  I find this extremely annoying, but certainly manageable once you understand the language - and maybe even something you can use effectively.  But I found his example so contrived that I basically checked out.

Wednesday, July 29, 2015

Java FX Event Thread vs AWT Event Thread Brawl

So, I recently started working on a Java UI application focussing on my backend first, then the UI components.  I am not very good at making pretty swing UIs (very out of practice - but I was really active when Swing was in development - what was that, 1997?  :| ).  I have done a lot have dynamic web development over the last decade and am frankly shocked that swing UIs are so far behind.  A dynamic swing UI to match a trivial web interface would be a LOT of work.  So, my first cut at my UI was targeted at behavior and testing, which was a substantial effort - I would have thought automated unit testing in the user interface would be in a better state than it is.

Almost every substantive UI testing platform appears to be abandoned (uispec4j, abbott, others I can't remember anymore) so I decided to build my own support as I needed it (Not building a generified UI unit testing framework - just what I needed).  The one good thing that came out of this approach was I realized testing the UI through the UI - as a user would or a record/playback testing method - was a big mistake.  I was decomposing my user interface as any good developer would do, but my testing was completely monolithic.  Instead, I started testing components at the finest grain and my tests became so much faster and easier to write with less bulk.  I also wired components together to rely on messages between objects rather than having handles to each other.  Sound familiar?  That should have been my approach from the start.

At any rate, I was going along, and decided it was time to make the user interface better, and I thought it might be time to look at Java FX.  One of the major factors was Oracle choosing FX as the future direction for java, but also the ease with which you can externalize the building of the user interface into fxml files.  That is huge.  I can use a builder and not be tied to a tool like eclipse or IntelliJ - big win.

I made a refactor which permitted me to transition from swing to Java FX as it seemed desirable, and even encouraged with the addition of JFXPanel.  This seemed ideal since rewriting the entire UI all at once sucks.  Well, this sucks worse.  The Java FX Event thread and AWT Event thread are entirely incompatible - so threading in the UI is a nightmare.  Consider as an example a Swing Button action handler which needs to update the state of an FX node - you would have to do that asynchronously, you can't call PlatformImpl.runAndWait from the AWT event thread - it will hang a lot of the time.  But if your button action handler needs to wait until the FX node is complete updating - such as if the update triggers another event handler - you have to do it all asynchronously with a lot of calls back and forth into the different event threads and you are left with a real mess.

To compensate - I have had to convert all messaging in the GUI to asynchronous - which makes unit testing a major hassle because obviously test code needs to wait until things are done before making assertions.  The bottom line to me is not to do this.  Transitioning to Java FX should be done at least at the Frame level - or Stage in Java FX parlance - and don't let messaging in the GUI depend on passing between the different systems.

Tuesday, June 16, 2015

Maven dependency ranges must die!

When I first read about the capability of maven to loosely depend on an artifact using version ranges, I thought, "Wow, that's pretty cool!  Why doesn't everyone do that?"  After all, who wouldn't want the latest version of newly released awesomeness?  By way of example, this is how a dependency in maven usually looks, excerpted from Stefan Birkner's excellent JUnit system rules project:

<dependency>
<groupId>com.github.stefanbirkner</groupId>
<artifactId>fishbowl</artifactId>
<version>[1.1.1]</version>
<scope>test</scope>
</dependency>

This means your project depends on version 1.1.1, exactly, of something known as fishbowl in the group of things known as com.github.stefanbirkner.  The brackets around the version number are not usual, and are in fact redundant since they specify the same thing as <version>1.1.1</version> - that version and that version alone.  Going on further in the pom, we find this:

<dependency>
<groupId>junit</groupId>
<artifactId>junit-dep</artifactId>
<version>[4.9,)</version>
</dependency>

This construct is altogether different.  It specifies a dependency on the artifact known as junit in the group known as junit, but allows for any version greater than or equal to 4.9.  The bracket on the left is an inclusive operator and the parenthesis on the right is an exclusive operator.  The comma allows for any later revision.  By way of example, (4.9,5.0) would mean any version after but not including 4.9 but before and not including 5.0, and (4.9) would mean any version greater than and less than 4.9.  That wouldn't work at all.

This seems pretty powerful, but . . .

I have recently come 180° in my thinking about this.  I now hate them with a passion - for two very good reasons.

Awesome Reason I

This one is purely idealogical, which is not to say that it is without merit, it's just a caveat that it may be debatable.  If you depend, for instance, on apache commons-io 2.3, what reason do you have to expect it to work with 2.4?  Or even 2.3.1?  What assurances do you have from that developer community that 2.3.1 will not introduce a bug which impacts your library?  Certainly by version 2.4 the API might change and break compatibility with your code.  This is unpredictable and should not be part of a stable, release build.

Awesome Reason II++

This one is the biggie, and also exceedingly pragmatic.  The aforementioned system rules library, which while otherwise awesome, includes a dependency on junit 4.9 and onwards.  In a practical sense, though, depending on system-rules exposes my builds to periodic failures that are very difficult to track down or diagnose.  Just today I got this error again:

[ERROR] Failed to execute goal on project ssc-cli: Could not resolve dependencies for project org.bitbucket.bradleysmithllc.star-schema-commander:ssc-cli:jar:ssc.1.C: Failed to collect dependencies at com.github.stefanbirkner:system-rules:jar:1.9.0 -> junit:junit-dep:jar:[4.9,): No versions available for junit:junit-dep:jar:[4.9,) within specified range -> [Help 1]

What does this mean?  Why is it happening?  Well, after being plagued with this for a long time, I finally tracked it down.  Some transitive dependency of my project keeps retrieving crapped-up versions of junit, in this case 4.11-beta-1, which satisfies the dependency to be greater than or equal to 4.9, but is not an actual release - it is something that made it to central and then somehow into my repository.  My only (reasonable) recourse is to go to my local repository and delete the junit group tree (~/.m2/repository/junit) and rebuild.  Guess what happens next?

[ERROR] Failed to execute goal on project ssc-cli: Could not resolve dependencies for project org.bitbucket.bradleysmithllc.star-schema-commander:ssc-cli:jar:ssc.1.C: Failed to collect dependencies at com.github.stefanbirkner:system-rules:jar:1.9.0 -> commons-io:commons-io:jar:[2.0,): No versions available for commons-io:commons-io:jar:[2.0,) within specified range -> [Help 1]

Yep, you guessed it - another broken dependency range - this time apache commons-io.  Repeating the same process, I delete my cached commons-io artifacts (~/.m2/repository/commons-io) and now my project builds.

I do not know why exactly this keeps happening - and I am sure that there are many things that could be done to fix it - like track down bad dependencies and fix everyone else's poms, but that isn't an option in most cases nor is it even something I want to do.  My project has an explicit dependency on junit 4.11, which satisfies >= 4.9, so I don't know why it would consider any other version.  The bottom line is that there is no way to predict when a library will break compatibility with yours, and you should not try to anticipate when that will happen.  Builds must be stable and reproducible, and dependency ranges violate both of those goals.

Friday, June 5, 2015

Snob overflow . . .

Okay, another one of my many pet peeves. When people ask questions to Stack Overflow, the community often incorrectly assumes that you are too stupid to ask a real question and instead talks down to you and won't give a straight answer, even if there is one.

Here is a case-in-point: how-to-release-all-permits-for-a-java-semaphore

The question was immediately met with contempt: "What do you need this piece of code for?". This question was not asked for clarification, but so that the discussion could go in a completely different direction. The Stack Overflow moderators are such Nazis about intervening: "This is not a question!", "This is a survey!", "These are opinions!", "This is a duplicate!" - that I am surprised they don't get upset in this situation, because you have a clear question posed, and the selected answer goes in a completely different direction. Rather than answering the question "How to release all permits for a Java Semaphore", they answered the question "How do I better design my code to keep my thread pool in sync?"

The simple answer is:

semaphore.drainPermits();
semaphore.release(totalNumPermits);

Again, whether that discussion is valuable or not, it does not answer the very straightforward question that was asked.

Friday, May 8, 2015

Sonic, What's up with your foam cups??

I have been noticing for the past few months that my Route 44 styrofoam cups from Sonic in OKC have the annoying 'feature' that they leak through the pores in the foam. I have noticed this many times - and is it ever annoying. Here is a sample from the cup I am using right now. This cup is probably two or three days old, picked up at the Bricktown Sonic:
Those little drops look like normal condensation, but they are actually water escaping through the cup. I have to keep a paper towel under my drink at all times or else my desk will be all wet. In years past I could keep the cups for a long time and this would not happen. Very strange and not a little annoying.

Monday, May 4, 2015

Java Synchronization. What's the big deal?

Throughout my career as a Java developer, I have read a non-trivial amount of code related to minimizing the impact of synchronized code blocks.  The topic of thread safety is extremely complex, and must be embarked upon carefully.  In some cases, just declaring lack of thread safety can simplify a project immensely, E.G., java swing, but there are times when it can't be avoided without introducing a lot of complexity on the other side of the API.  That's not what I am referring to, however.  Consider double-checked locking.  This technique is often used simply to reduce the amount of time it takes to call an accessor.  To illustrate, I wrote the following chunk of code:

import java.math.BigDecimal;
public class Main {
 public static final long TEST_COUNT = 1000000000L;
 public static void main(String[] args) {
 long r = 0;
 long startSync = System.currentTimeMillis();
 for (long i = 0; i < TEST_COUNT; i++)
 {
 r += getSync();
 }
 long stopSync = System.currentTimeMillis();
 long startUnsync = System.currentTimeMillis();
 for (long i = 0; i < TEST_COUNT; i++)
 {
 r += getUnSynch();
 }
 long stopUnsync = System.currentTimeMillis();
 BigDecimal syncTotal = new BigDecimal(stopSync - startSync);
 System.out.println("Sync took (" + syncTotal + ") ms., or (" + (syncTotal.divide(new BigDecimal(TEST_COUNT)).multiply(new BigDecimal(1000))) + ") microseconds average.");
 BigDecimal unsyncTotal = new BigDecimal(stopUnsync - startUnsync);
 System.out.println("Unsync took (" + unsyncTotal + ") ms., or (" + (unsyncTotal.divide(new BigDecimal(TEST_COUNT)).multiply(new BigDecimal(1000))) + ") microseconds average.");
 }
 private static synchronized long getSync()
 {
 return System.currentTimeMillis() % 100L;
 }
 private static long getUnSynch()
 {
 return System.currentTimeMillis() % 100L;
 }
}

When I ran it, this was my output:
Sync took (98345) ms., or (0.098345000) microseconds average.
Unsync took (43530) ms., or (0.04353000) microseconds average.


The difference here is 50 or so nanoseconds per access. Unless you are writing a high-performance application like a 3D game or database, I just don't see how this can even be worth discussing. Almost every application I write would involve calling these accessors on creation, which means 40 or 50 times during an entire application life, or even if it is tied to user requests like in a service or web application, 50 microseconds per request will be dwarfed by the amount of time the request itself takes. If there is a database access, just opening a connection that takes 1 millisecond to open will be 20,000 times slower than a synchronized accessor.

As engineers we sometimes like to focus on the really fun stuff, like generated bytecode or network packets or even CPU states, but synchronization overhead doesn't even seem like it's worth the time to type out.

PS: Have I said how much I hate the blogger editor???

Friday, April 24, 2015

Star(schema) Commander, Iteration 4

So, thus far I have added groupings, aggregates and degenerate dimensions to the core, and I have added references to JxBrowser which added 200MB to the project. :(

The UI for the data explorer is challenging.  I don't want to spend the rest of my life on it but I also don't want to produce an ugly piece of crap reminiscent of old Linux Motif/Tcl/Tk apps.  The Java UI is much more limiting than I remembered - most new gestures aren't accounted for, even in the newest stuff.  Maybe JavaFX?

Sunday, March 29, 2015

Star(schema) Commander, Iteration 3

So much for micro releases.  :|

So far I have experienced a few interesting things:

  • Micro releases are not that satisfying when doing initial development - especially across three interconnected projects - core, cli and gui libraries.
  • Unit testing user interfaces really sucks.  I tried to find something but no solution seems to be around for very long.  In the end I created my own UI framework based on standalone components and messaging which made testing very easy and meant the runtime app just had to wire them together properly.  It also achieved a nice encapsulation of the different UI parts.
  • It is WAY too easy to get stuck testing every detail in a UI and it can eat up a LOT of time because everything you have to do is a new one-off.
  • The internet is not very helpful on the issue of user interface testing.  If I have to read another lecture about separation of responsibility and how you should test the domain layer, not the UI objects, blah blah barf, I will delete the internet.  Guess what, people? User interfaces have requirements as well and those must be tested with the same level of reliability as other parts.
  • When testing a user interface, there is a lot you have to let go.  Unit testing Java code can be very granular and specific, but if you try that in a user interface it will be a train-wreck.  E.G., if a table has headers that read "Name", and "Schema", testing those is going to add more semi-useless tests and will make any change to the UI break way too many tests.  Besides which I would like to refactor my UI (changing lists to tables, etc) without extra tests breaking.
  • I did manage to temper my desire to create the perfect user interface library.  I simply created what I needed and refactored as I realized that I needed more functionality.  There is a word for that but it escapes me at the moment (and most other times) ;)  . . .
  • I am toying with the idea of rewriting my UI using JxBrowser - a Java library for using an embedded Chromium container.  My Java desktop apps look so crappy and take so much work to wire together and are therefore resistant to change, and HTML makes a nice container for UI code - as compared to Java code.  I am concerned about the extreme commercial nature of the project - $1600 per license minimum; I don't know what they think they are providing that is worth that price - even if I do have a free open source license at my disposal.

Thursday, March 5, 2015

YAJUEHP - Yet Another JUnit Exception-Handling Post . . . *yawn*

I can't imagine anyone will find this useful when it is so tiresome to me, but after a jaunt in UI Testing purgatory I had to go back and test some plain old library code, but this time with a new twist.  I have been using the rather awesome ExpectedException class with nice results.  The Code Under Test in this case, however, threw InvocationTargetException's with wrapped cause's which made that approach too brittle.  I found this nice post about it which solved my issue:

JUNIT EXPECTEDEXCEPTION RULE: BEYOND BASICS

Toward the bottom there is a nice discussion of verifying causes.  I found another article he wrote comparing various exception strategies in JUnit here:

6 WAYS OF HANDLING EXCEPTIONS IN JUNIT. WHICH ONE TO CHOOSE?

I thought these were pretty handy - hopefully someone else will as well.

Wednesday, February 4, 2015

Star(schema) Commander, Iteration 2

I got version 1.1 and 1.2 out in the same night.  I have dimensions and reporting areas, and a mechanism to import dimensions from a database.  Not too useful yet, but facts are coming.

Saturday, January 24, 2015

JUnit System Rules

I found this today - it was very helpful for some testing I was doing.

System Rules

It has all kinds of cool stuff in it, but what I was looking for was a way to have tests override system properties (Specifically to test code which relied on user.home) and after each test completes the properties are restored.

Wednesday, January 21, 2015

Star(schema) Commander, Iteration 1

I have created an API, a maven project, and set it up for maven central synching.  That's not much value, but it is a lot of legwork.

For the next release I am going to aim for at least the ability to create a profile.

Tuesday, January 20, 2015

Star(schema) Commander, Iteration 0

Because I am constantly writing queries against dimensionally modeled star-schemas, I decided to write a small app to make the process easier.  I thought I would approach it in an agile manner - incorporating small releases and focussing on delivered value.

I also thought it might be interesting to post my experiences mainly to help keep myself on task.  My goal is to have a very usable UI - but I have tried that before and I think it will end up like a messy iOS app with code scattered all over user interface components.  It would also take a long time for me to be able to do anything meaningful - and an application opening a window is not value.  E.G., It might take months to make the UI work, but probably only a few weeks to have a command-line tool I can use to generate queries.  That would be a win by itself.

So, anyway, here I go.

This is the bitbucket project (currently blank):  https://bitbucket.org/bradleysmithllc/star-schema-commander

This is where I will actually document it (also currently blank): https://etlunit.atlassian.net/wiki/display/STAR/StarSchemaCommander

Monday, January 5, 2015

The Opiate of the Masses . . . ?

Karl Marx once said, in effect, that Religion is the opiate of the masses.  To be exact, this is the English translation of the quote according to Wikipedia:

"Religion is the sigh of the oppressed creature, the heart of a heartless world, and the soul of soulless conditions. It is the opium of the people."

I was thinking about this recently because I had an experience which brought this quote to mind, and about how off target this is - at least in our time.


Religion, or Faith?


He was wrong primarily in mistaking religion for faith.  It is tempting to give Marx the benefit of the doubt and assume that he understood the difference, but I don't believe that someone who has never experienced genuine faith in something greater than oneself can really know what it is.  Faith is not a drug to dull our senses and numb our emotions - it is a genuine devotion.

He further believed that he could substitute devotion to the collective - or more specifically the government institution - for a genuine faith.

Why is he wrong?  Because Opium induces a delirious high - perhaps helping the addict to release cares due to the drug.  True faith, however, yields hope - or, in the words of the Apostle Paul:



Galatians 5:22-23
But the fruit of the Spirit is love, joy, peace, forbearance, kindness, goodness, faithfulness, gentleness and self-control. Against such things there is no law. 
Galatians 5:21-24 (in Context) Galatians 5 (Whole Chapter)

If you compare this list to what Opium use produces, the comparison becomes laughable:


  • Lying or other deceptive behavior
  • Sudden worsening of performance in school or work, including expulsion or loss of jobs
  • Loss of motivation and apathy toward future goals
  • Withdrawal from friends and family, instead spending time with new friends with no natural tie
  • Repeatedly stealing or borrowing money from loved ones, or unexplained absence of valuables
  • Hostile behaviors toward loved ones, including blaming them for withdrawal or broken commitments
  • Regular comments indicating a decline in self esteem or worsening body image


The true Opiate of our Times


So, if religion is not the opiate of our times, then what is?  I mentioned earlier that an experience I had brought this to mind.  I was feeling a little down at work (combination of stress and disillusionment with lack of ability to finish projects), and I put on some music - specifically Schubert's Winterreise.  I immediately felt an emotional ambivalence - the very effect I had hoped for.  I realized then how we use music in so many different ways in our world - from entertainment to mood alteration and even behavior modification.  Looking at it objectively, there are very few times in our lives when there is complete silence.  Music in the car, in the elevator, when we are on hold on the phone, in movies, blaring at sporting events in between any pause in action, etc.  In fact, situations which lack music seem lackluster and boring.  Clearly this pales in comparison to opium use, but that was Marx's choice, not mine, and I believe it is a more appropriate comparison than religion since the goal of music is similar, even if the results are dissimilar.

Our cultural infatuation with Music-like sounds (Most of the time not musical at all) was demonstrated to me when I went to an OU / Texas game at the Cotton Bowl.  Music was blaring the entire time there wasn't action directly in front of us - and it was horrible.  An acoustic assault on our senses.  Just because I love football, does that automatically mean I like AC/DC??!?!?  I am not sure the intention was even to entertain musically, but rather to incite an intensity and rush that is expected of a big-time football game.  It also aids some drunken fans in getting up for the stupid fights that sometimes occur afterwards.

The worst part is that I have spent a significant portion of my life as a musician, and music lover, which means in affect that I am both a dealer and a user.

Hi.  My name is Brad - I am an addict.

Exceptional JUnit Rules

I recently got aggravated at the JUnit capability for handling and testing expected exceptions.  Usually it looks like this:

@Test(expected = IllegalArgumentException.class)
public void testBadConditions()
{
}

That works just fine when first assembled, but what happens when that same exception class is thrown by a different piece of code, for a different reason?  The answer, the test passes.  This hit me when I was implementing a builder pattern in my etl-unit framework using a TDD approach, and my tests for validating parameters would pass, but when I added more validation the same exceptions were being thrown for different reasons (because I altered the order of validation) so the tests were still passing, but parts of code were being hidden from test cases and were no longer being covered.  When using TDD you tend to lean heavily on the unit tests, and things like this can be a big problem (tests passing when they should not).  I like to know right away when I have broken something.

I had a couple of options that I knew about:


  1. I could use a different exception class (or subclass) for each validation rule.
  2. I could use try/catch blocks in my tests and manually check the exception class and message.
Option (1) sucked, and in some cases I couldn't do it anyway, so I ruled that right out.  The second would allow me to use distinct messages to make them verifiable, but made for ugly tests (my opinion):

@Test
public void testBadConditions()
{
  try
  {
    causeAnError();
    // in case an exception is not thrown
    Assert.fail();
  }
  catch(IllegalArgumentException exc)
  {
     Assert.assertEquals("expected message", exc.getMessage());
  }
}

I didn't care too much for that - way too much noise in my tests.  I initially googled it and found, as expected, a bunch of irritating, condescending posts about why this is always bad and JUnit would never implement this.  The @Test annotation indeed does not support adding a message, but I have been using JUnit rules a bit recently and I hoped there might be a rule for this.  Suspecting that it would be called ExpectedException, I googled for that.  To my delight, I found it.  Here is an example of the above test using this rule:

@Rule public ExpectedException expectedException = ExpectedException.none();

@Test
public void testBadConditions()
{
    expectedException.expect(IllegalArgumentException.class);
    expectedException.expectMessage("expected message");

    causeAnError();
}

@Test
public void noExceptionThrownTest()
{
 ...
}

I really like the way this looks.  It is functionally equivalent to the previous example.  The declaration of the @Rule is initialized with ExpectedException.none() so that the default state before each test is not to expect an exception, and noExceptionThrownTest does not expect an exception as usual.  Then, at the start of the test, as with other JUnit rules, you tell the rule to expect an exception class and then give it the message to expect.

Other things you can do with this rule are specify a regular expression for the message, and assert an exception cause class type.

I'm not sure I like this better than having it in the @Test annotation, but I do like it way better than my alternatives.

Ignoring JUnit

In the past I have been against ignoring broken tests (usually accomplished by commenting-out the @Test annotation) - usually looking something like this:

//@Test
public void brokenTest()
{
  . . .
}

Generally when I have been involved in a project where this happens those tests get ignored for so long that they will eventually be thrown away.

Recently, however, overwhelming demand for this feature in my etl-unit testing framework (I.E., it was suggested by one developer and I liked it) meant I had to do some refactoring. When I was in the middle of  changing some code in a common module I wanted to get an idea for where I was in the bigger project.  I suspected JUnit had an @Ignore annotation and I was right.  So, instead of the above, this is what I had:

@Ignore
@Test
public void brokenTest()
{
  . . .
}

I liked this much more, for a few reasons:  (1) my IDE, Intellij IDEA, will run all the tests, but leave the ignored ones highlighted to call attention to them, (2) a simple search of the project will reveal everywhere this has been used, (3) this serves as a reminder to me of how much work I have left to do, and (4) I can do a full multi-module build to evaluate parts of implementation as I go.

I do prefer my own implementation for a few reasons.  The JUnit @Ignore annotation has an optional value attribute which can hold a reason for the ignore.  In etl-unit, the @Ignore annotation has a mandatory reason attribute which should contain a description of what is broken, etc (reason seems so much better to me - value is too vague).  Etlunit goes a step farther, however, and adds an optional reactivate-on attribute which holds a date after which time the test is no longer ignored, but rather than executing will throw an ERR_IGNORE_EXPIRED error, or a user-specified error or failure can be substituted, the latter being used when you would prefer for the test to fail rather than an error being generated.

I really like the reactivate date since these kinds of tests can easily be forgotten about, and when your continuous integration server builds start failing you will have a not-so-gentle reminder.