Skip to content
Advertisement

Junit test of a class requires objects of other classes

I have a class defined as such:

JavaScript

Simply put, there is an algorithm that requires input from other class, the mapObject, which is also another self-written package by me.

My question is, apart from

JavaScript

in junit that allows me to initialize a fixture in

JavaScript

Are there any better ways?

Advertisement

Answer

It’s probably better to create the input object (i.e. the mapObject[][]) in the test case itself, rather than in a @Before method. This allows you to create several test cases with different input objects.

Ie

JavaScript

As a note, it doesn’t feel right that the input is a mapObject, but the actual algorithm works on an aNode[][]; but it’s hard to tell without knowing the context of the code.

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement