Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Join us in Toronto Sept 9th for Qlik's AI Reality Tour! Register Now
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

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
Labels (3)
8 Replies
Anonymous
Not applicable
Author

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
Anonymous
Not applicable
Author

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.
Anonymous
Not applicable
Author

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 0683p000009MACn.png
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 0683p000009MA9p.png
Hope it helps
regards
laurent
Anonymous
Not applicable
Author

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 0683p000009MACn.png
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 0683p000009MA9p.png
Hope it helps
regards
laurent
Anonymous
Not applicable
Author

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
Anonymous
Not applicable
Author

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
Anonymous
Not applicable
Author

very simple 0683p000009MA9p.png
use tLibraryLoad
regards
laurent
Anonymous
Not applicable
Author

Thank you.
Will try it later. 🙂
very simple 0683p000009MA9p.png
use tLibraryLoad
regards
laurent