转换 JUnit 测试
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
精心设计的软件项目通常有许多单元测试来验证它们。对于 Java 项目
JUnit 是最常见的单元测试框架。J2ObjC 提供
支持转换单元测试,因此可在 OS X 上作为二进制文件执行。这样可以验证
翻译没有更改翻译类的语义(行为),并验证
转换后的代码作为 Objective-C 代码运行。
翻译测试
在类路径中使用 junit.jar
运行 j2objc。该 jar 文件的副本包含在 j2objc 中
分布,命名为 lib/j2objc_junit.jar
:
# Example: J2ObjC bundle unzipped into a ~/tools directory
export J2OBJC_HOME=~/tools/j2objc
${J2OBJC_HOME}/j2objc -classpath ${J2OBJC_HOME}/lib/j2objc_junit.jar MyUnitTest.java
关联测试
使用libjunit.a
lib/
编译器的 -l
标志:
${J2OBJC_HOME}/j2objcc -ObjC -o mytest -ljunit MyUnitTest.m
运行测试
使用一个或多个测试和/或测试套件的名称运行测试可执行文件,例如 JUnit 测试
在 Java 中运行。名称可以是完全限定的 Java 名称(包含软件包),也可以是等效的
翻译后的名称。例如,com.company.MyUnitTest
测试类也可指定为
ComCompanyMyUnitTest
。
./mytest org.junit.runner.JUnitCore com.company.MyUnitTest # or com.company.Test2
org.junit.runner.JUnitCore
是 JUnit 的测试运行程序之一,可以运行 JUnit3 或 JUnit4
测试。不过,您也可以使用任何其他 JUnit 运行程序。
构建测试
下面这个示例说明了如何使用 make
构建和运行大量单元测试。
j2objc/jre_emul/tests.mk,在
项目源代码。
如未另行说明,那么本页面中的内容已根据知识共享署名 4.0 许可获得了许可,并且代码示例已根据 Apache 2.0 许可获得了许可。有关详情,请参阅 Google 开发者网站政策。Java 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2024-10-14。
[[["易于理解","easyToUnderstand","thumb-up"],["解决了我的问题","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["没有我需要的信息","missingTheInformationINeed","thumb-down"],["太复杂/步骤太多","tooComplicatedTooManySteps","thumb-down"],["内容需要更新","outOfDate","thumb-down"],["翻译问题","translationIssue","thumb-down"],["示例/代码问题","samplesCodeIssue","thumb-down"],["其他","otherDown","thumb-down"]],["最后更新时间 (UTC):2024-10-14。"],[[["J2ObjC enables the translation of Java unit tests, written using JUnit, into Objective-C code for execution on OS X."],["This translation process ensures that the original Java code's behavior remains consistent after conversion and validates its functionality within the Objective-C environment."],["Developers can utilize J2ObjC's tools and libraries to compile, link, and execute these translated tests, similar to running JUnit tests in Java."],["Comprehensive build processes for managing and running numerous unit tests can be established using examples like the 'tests.mk' file in the J2ObjC project source."]]],[]]