简体   繁体   English

如何在Eclipse中使用JUnit4测试jar文件?

[英]How can I test a jar file using JUnit4 in Eclipse?

I need to black box test a jar file provided to me. 我需要对提供给我的jar文件进行黑盒测试。

I've created a new project and added the jar file, let's call it test.jar to the build path. 我创建了一个新项目,并添加了jar文件,我们将其称为test.jar到构建路径。 I don't know how I'm supposed to access the methods to test them because it is a jar file instead of a java file. 我不知道该如何访问测试方法,因为它是jar文件而不是java文件。

How can I create a JUnit test case that can access the methods of the jar so I can test them? 如何创建可以访问jar方​​法的JUnit测试用例,以便对其进行测试?

If the JAR file is in your project you should be able to test it just like you would test classes that you had the source code for. 如果项目中包含JAR文件,则应该能够像测试具有源代码的类一样对其进行测试。 Create test classes for the classes in the JAR and create test cases for the public methods of those classes. 为JAR中的类创建测试类,并为这些类的公共方法创建测试用例。

If you're using Eclipse, you should be able to expand the Referenced Libraries entry in the Package Explorer window to see what the package structure of the JAR is, and what classes and methods there are. 如果使用的是Eclipse,则应该能够在Package Explorer窗口中展开Referenced Libraries条目,以查看JAR的包结构是什么,以及类和方法。

您可以为任何其他类创建单元测试的方式相同:导入类,实例化对象并调用其方法。

Simply add the library ( test.jar ) to the classpath (build path). 只需将库( test.jar )添加到类路径(构建路径)中。 If you see it in the package explorer and in your on project, right click and you should find some Add to build path.. 如果在包资源管理器和在上项目中看到它,请右键单击,然后应该找到一些“ 添加到构建路径”。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM