Adding custom junit test jar
Im taking college CS classes, and our prof gave us a supplementary jar that provided us additional testing methods, like grabbing console text, etc.
To add it, I went to File > Project Structure > Libraries (under the Project Settings header) and then I added the new jar as a library, just like junit 4.12 is. However, when I call the methods provided to us in one of the classes in the jar file (in this case assertEquals(double expected, double actual)), I get an error saying I'm using the method incorrectly, and must include a third argument double delta. However, the the jar provides us an overloaded assertEquals that does not require the third argument, thus it is clear the imported class's methods are not being accessed. When I run this from the command prompt I get told that the imported class can't even be found. The online help section is not clear on how to add an additional testing jar. Any help is deeply appreciated as our CS department does not provide support for IntelliJ
Please sign in to leave a comment.
The library must be added to the module dependencies instead of the original one: http://www.jetbrains.com/idea/webhelp/configuring-module-dependencies-and-libraries.html.
Thank you Serge. Does that rule stand for any additional jars that I'll ever need to use?
Yes, all the jars should be added to the module dependencies. You can first organize them in libraries if you want, but then don't forget to add the library to the dependencies of your module.
Serge, I did so, however I'm confused a little bit. JUnit 4.12 is shipped with IntelliJ, and is set as an external library, and I can use it easily, however on the dependencies dialog in the modules tab, I have 2 junit 4 libraries, and neither has the checkbox toggled as a dependency. Is JUnit a special case because it is shipped with IntelliJ?
If JUnit is not checked as a module depenency, would that explain why I can't run junit tests from cmd prompt?
Sorry for all the questions. IntelliJ has so many moving parts and I'm still trying to learn em all.
Not sure what you mean. If you see it in the dependencies tab, it should work automatically. There is no checkbox. Checkbox is used to export dependencies so that if another module depends on this module it can also access the dependencies of this module.
Oh yep, I misread lol. My supplementary jar is now a module dependency and I can access everything. Thank you serge.
One final question: In the dependency tab I have JUnit 4 entered in twice. One of the entries has a path leading to the IntelliJ install location and has the junit 4.12 jar and hamcrest, the other one has a path leading to my intelliJ project and has both the junit 4.12 & hamcrest.
Is there a reason that they are on there twice? Or perhaps some resource on the site that would mention why so I can educate myself on why they are there twice?
You don't need the duplicate libraries there, so leave just one instance.
There is intention action to add JUnit dependency from IDEA installation, probably you have triggered it and then also added another library from the project location.
Which one should I delete? The one that contains paths to the IntelliJ installation directory, or the one with paths that lead to my project?
Again, I apologize for the multitude of questions, and thank you for your continued assistance.
It's up to you. For portability I'd use the one from your project directory.
Thank you very much for your patience and help Serge. I have everything figured out now.