Sunday, May 6, 2012

Using JUnit to Test LIbraries in Talend

Lately, I've been working on developing a data cleansing library in Talend. I developed the library using Talend User Routines then added the calls to the library in my components. It works real well so far. In fact, you can write tests for the library function using JUnit. I found Bekwam Data as a Service's post  to be very helpful in setting JUnit up. Basically, you have to make sure you download the latest JUnit jar and import it in you Talend. Simple.

Once you have that set, you'll notice that if the test fails the JUnit function throws an error like such

Exception in thread "main" java.lang.Error: java.lang.Error: java.lang.NoClassDefFoundError: org/junit/ComparisonFailure
at data_load.sandbox_0_1.Sandbox.tFileInputDelimited_6Process(
at data_load.sandbox_0_1.Sandbox.runJobInTOS(
at data_load.sandbox_0_1.Sandbox.main(
Caused by: java.lang.Error: java.lang.NoClassDefFoundError: org/junit/ComparisonFailure
at data_load.sandbox_0_1.Sandbox.tRowGenerator_10Process(
at data_load.sandbox_0_1.Sandbox.tFileInputDelimited_6Process(
... 2 more
Caused by: java.lang.NoClassDefFoundError: org/junit/ComparisonFailure
at data_load.sandbox_0_1.Sandbox.tRowGenerator_10Process(
... 3 more
Caused by: java.lang.ClassNotFoundException: org.junit.ComparisonFailure
at Method)
at java.lang.ClassLoader.loadClass(

It is a clunky error message for something trivial such as a test failure. You can catch the message and print out the relevant error: 

              assertEquals("Name of Test Case:","EXPECTED TEXT",Cleaning.cleanCompany("SOME TEST INPUT"));  
           } catch(org.junit.ComparisonFailure ex){  

Junit puts the non-matching substring within square brackets. 

The one annoying thing with this approach is that you can't get the number of all failing test cases as the error gets caught even if a single test case fails. Talend stops execution immediately and you see the JUnit message.

I'm also debating on the idea of moving the library development entirely in eclipse so I can use JUnit plugins to test my library.

No comments:

Post a Comment