One Star

User defined function(routine)

I am a newbie to Talend.
I know that I can create user defined routine(functions) using Java code.
What's the easiest way to do unit test for the function inside Talend Open Studio?
Thanks
8 REPLIES
Moderator

Re: User defined function(routine)

Hi,
We don't understand your requirement very well, what's the purpose of "unit test". Do you mean how to call your routine in Talend Open Studio?
Best regards
Sabrina
--
Don't forget to give kudos when a reply is helpful and click Accept the solution when you think you're good with it.
One Star

Re: User defined function(routine)

Thanks for your reply.
My question is: for example, I need create my own function
myFunction()
How to test that myFunction() is doing what I expected? Can I do code testing inside TOS?
Or I have to test outside TOS? like Eclipse?
Thanks again.
Seventeen Stars

Re: User defined function(routine)

hi,
you can use Eclipse to driven test and construct your routine.
Export in jar format , add jar to Talend lib or load jar file with Talend component and Test with différent user cases.
Or in Talend, create the routine and use somme assertion for each user case.
First test failed, because nothing has been developped.
    public static Integer addition(Integer nbre1,Integer nbre2) {
Integer result = 0;

return result;
}

In my first user Case , I've fixed 2 values of integer to add at 10.
in tAssert i'm wating for ... 20 Smiley Happy
Run first failed (see result with tAssertCatcher).
Than begin to code your routine.
    public static Integer addition(Integer nbre1,Integer nbre2) {
Integer result = 0;

result = nbre1 + nbre2;

return result;
}

Run test again
Assert Catcher tell is Ok now.
Test with if a String is passed to your routines, or null values , or ..... etc Smiley Wink
Hope it helps
regards
laurent
One Star

Re: User defined function(routine)

Thanks for the helpful information.
Originally, I would like to test the function only before calling it inside the ETL job.
According to the first way you mentioned, maybe I can try to do coding in Eclipse, then import them into TOS...

hi,
you can use Eclipse to driven test and construct your routine.
Export in jar format , add jar to Talend lib or load jar file with Talend component and Test with différent user cases.
Or in Talend, create the routine and use somme assertion for each user case.
First test failed, because nothing has been developped.
    public static Integer addition(Integer nbre1,Integer nbre2) {
Integer result = 0;

return result;
}

In my first user Case , I've fixed 2 values of integer to add at 10.
in tAssert i'm wating for ... 20 Smiley Happy
Run first failed (see result with tAssertCatcher).
Than begin to code your routine.
    public static Integer addition(Integer nbre1,Integer nbre2) {
Integer result = 0;

result = nbre1 + nbre2;

return result;
}

Run test again
Assert Catcher tell is Ok now.
Test with if a String is passed to your routines, or null values , or ..... etc Smiley Wink
Hope it helps
regards
laurent
Seventeen Stars

Re: User defined function(routine)

in my example (in TOS), you're coding your routines directly in Talend, but separatly from the use of that routine
in your ETL process (in a tMap for ex).
By this way, you're testing each new user case and result is directly safe in the routine you're using in your process.
regards
laurent
One Star

Re: User defined function(routine)

Yes, I understand, basically you created a very simple job to run the test. It's a good idea.
BTW, as you said of another way, do you have any example about how to import jar file into TOS? It seems I couldn't find it.
Thanks

in my example (in TOS), you're coding your routines directly in Talend, but separatly from the use of that routine
in your ETL process (in a tMap for ex).
By this way, you're testing each new user case and result is directly safe in the routine you're using in your process.
regards
laurent
Seventeen Stars

Re: User defined function(routine)

very simple Smiley Wink
use tLibraryLoad
regards
laurent
One Star

Re: User defined function(routine)

Thank you.
Will try it later. :-)
very simple Smiley Wink
use tLibraryLoad
regards
laurent