I have the following code that creates an array of three ojbects repeatedly and saves them into an array list, and I like to return from the method a Stream of these three objects (KdTree, RectHV, and Point2D) yes the last one is yet another array, but it matches the unit test method signature. I first like to know please if there is a better way of doing this, and then how I can return the stream of my original objects because right now Junit5 gives me the following error:
JUnit 5 has an ArgumentsProvider interface that you can implement to provide arguments to a @ParameterizedTest. The KdTreeArgumentsProvider class implements this interface and is bound to the range() unit test using the @ArgumentsSource annotation.
The problem appears to be that JUnit can't seem to bind the values of the kt, r and expectedPoints variables on line 30 to the parameters with the same name on line 38. I'm not sure what causes the problem.
Sam, if you can clean up the code, we can see if we can reproduce the problem. Pay attention to the following things:
Don't use File to access application resources. Instead, use Class.getResourceAsStream().
Test resources should be in src/test/resources, not src/main/resources.
Get rid of the instance fields of KdTreeArgumentsProvider. You can use local variables instead.
Good Morning and thank you for both replies,
I wanted to post the version that is now working better, but the only problem I have is that it only runs the last instance of the tests. The entire project is here. It is Maven project in Intellij. Now I see all the Objects in the array at the end of provideArguments() method, and the test runs but it only runs for the last batch. I also wanted to say that I did try flatMap() but I believe I ran into an issue of Object not supporting it. But I will have a look again. Given that there are a number of items in your last advice I did not try yet, if you feel I should give them a try, please just say something like "try it" or something, but regardless I will. The other item I wanted to mention is why I created the two Point objects and the one rectangle and keep adding them to the data. They are place holders for now, and my goal is to have the flexibility to test the same KdTree with different number and kinds of rectangles, and the expected result will be different number of Points. And I wanted to ask please how to set up my input files and parse them. I think I am going to use a Pipe to separate the points data from rectangles and the expected points, but if you have a favorite link or something I can follow I would greatly appreciate it. I am also wondering if I should setup a small database. I have run mySql in the past.Here is what I have now:
Thank you so much for the advice. I have moved my test files to src/test/resources/ and I just viewed a tutorial on how Class.getResourceAsStream() works. Re: your advice on removal of the instances, I intend to and will do so. I intend to add more logic to build different instances for each test.
I am also trying the getResourceAsStream() and it works as far as creating the tree I need, but I believe I still need an Object to pass my test data to the unit test method. So I think there was another reason you advised using this vs. File. Would you let me know please? Here is what I have:
You firghten me terribly. I would like to go home now. Here, take this tiny ad: