Junit test for testing a Node's functionality

#1

Hi Team,

I have a node which behaves like ‘CSV Writer’. It accepts an input table and writes out a csv file based on some logic.
Now, I have a method ‘writeCSV(BufferedDataTable inputTable)’. I need to write a junit test with a sample BufferedInputTable and test/validate the written csv file.
How can I create a BufferedDataTable in my junit test?
First of all, is this something that could be best tested with a junit test or test workflow?

Thanks
Ravikiran

0 Likes

#2

Hi @ravikiran,
you should create a testworkflow for situations where you test how your node iteracts with the more complex systems of the platform such as BufferedDataTable. Make use of the nodes in the KNIME testing framework:

If you need to create unit tests you might encounter situations where standard Junit tests will not work due to dependency issues, in those cases you can try running them as Junit plug-in tests.

best,
Gabriel

0 Likes

#3

Hi Gabriel,

Thanks for your answer.

Below is what I have in place:

  1. Created a fragment with extension as ‘org.knime.testing.TestcaseCollector’:

     <fragment>
        <extension
              point="org.knime.testing.TestcaseCollector">
           <TestcaseCollector
                 TestcaseCollector="com.schrodinger.workbench.ui.NodesTestcaseCollector">
           </TestcaseCollector>
        </extension>
     </fragment>
    
  2. Running the knime with args:
    knime -application org.knime.testing.UnittestRunner -destDir junit_test_results

Now in my test methods, if I need to create a sample BufferedDataTable, how can I do that?
BTW, is this not a junit plugin test?

0 Likes

#4

BufferedDataTable are not designed to be created directly, they depend on an execution context and do not really work in isolation. For testing purposes look at other implementations of the DataTable interface, See the answer bellow Junit test for testing a Node's functionality
best,
Gabriel

0 Likes

#5

Hi Gabriel,

Thanks for the response.
Looks like your last response is truncated. Could you please resend the complete response?

Thanks
Ravikiran

0 Likes

#6

Hi @ravikiran,
In my test cases, I use a DataContainer class to create an instance implementing the DataTable interface.

Hope this helps,
Fabrizio

2 Likes

#7

Hi Fabrizio,

Thanks for the pointers. Let me check this and get back to you.

Thanks
Ravikiran

1 Like