java 在idea中设置类路径以运行单元测试
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10939861/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Setting classpath in idea for running unit test
提问by Rachel
I am using openCSV
jar to work with csv present in my parser project, now I want to unit test my parser and for that I get call pass it to object of my parser class so that I can go ahead and do parsing.
我正在使用openCSV
jar 来处理我的解析器项目中存在的 csv,现在我想对我的解析器进行单元测试,为此我得到调用将它传递给我的解析器类的对象,以便我可以继续进行解析。
Now am getting java.lang.NoClassDefFoundError: au/com/bytecode/opencsv/CSVReader
, openCSV
jar is already present in the project but now if i try to run unit test, i get above mentioned error.
现在java.lang.NoClassDefFoundError: au/com/bytecode/opencsv/CSVReader
,openCSV
jar 已经存在于项目中,但是现在如果我尝试运行单元测试,则会出现上述错误。
How can i set project classpath in intellij idea so that I can run unit test having reference to all dependent jars.
我如何在 intellij 想法中设置项目类路径,以便我可以运行单元测试并参考所有依赖的 jar。
Thoughts?
想法?
回答by Paulius Matulionis
If you have different modules for your project and unit testing than you need to add dependency of that .jar also in your unit testing module.
如果您的项目和单元测试有不同的模块,那么您还需要在单元测试模块中添加该 .jar 的依赖项。
For e.g. When I am making project using IntelliJ I create modules.
for e.g. I have two modules: main
and test
. Than I create libraries for my main module and for my test module and add them into modules dependencies.
例如,当我使用 IntelliJ 制作项目时,我会创建模块。例如,我有两个模块:main
和test
。然后我为我的主模块和我的测试模块创建库并将它们添加到模块依赖项中。
I am using IntelliJ 10.5.4 so the path would be: File -> Project Structure -> Modules -> main -> Dependencies -> Add -> then I select created library.
我使用的是 IntelliJ 10.5.4,所以路径是:文件 -> 项目结构 -> 模块 -> 主 -> 依赖 -> 添加 -> 然后我选择创建的库。
Also you can add module dependencies to other modules and use their classes.
您还可以将模块依赖项添加到其他模块并使用它们的类。
Hope this helps.
希望这可以帮助。