如果您对这个答案投了赞成票,请也给 Szabolcs 投票,以向他的答案投赞成票。他在这方面提供了巨大的帮助。
MUnit 的位置取决于第一次使用 Wolfram Workbench 功能的顺序。 这只是一个理论,但它解释了为什么 find 最初无法找到 MUnit,但现在却找到了。 在我的系统上,MUnit 位于:
/Applications/Wolfram\ Workbench.app/configuration/org.eclipse.osgi/bundles/214/1/.cp/MathematicaSourceVersioned/Head/MUnit
使用 Wolfram Workbench 在您的系统上定位 MUnit:
- 创建一个调用您的代码的测试用例。
- 在测试用例测试的代码中放置一个断点。
- 调试测试用例。
- 一旦你停在断点处,继续单步执行代码,最终你会在单步到
TestID->"MyTest-20111230-L0X3S3"时单步执行Test.m。
- 将鼠标悬停在 Test.m 的选项卡上,您将看到 Test.m 的位置。
使用 find 在您的系统上定位 MUnit:
- 在 Wolfram Workbench 中创建一个测试用例。
- 打开终端并输入:
find / -name MUnit -print 2> /dev/null
find 结果:
/Applications/Wolfram Workbench.app/configuration/org.eclipse.osgi/bundles/214/1/.cp/MathematicaSourceVersioned/Head/MUnit
/Applications/Wolfram Workbench.app/configuration/org.eclipse.osgi/bundles/214/1/.cp/MathematicaSourceVersioned/Version5.2/MUnit
/Applications/Wolfram Workbench.app/configuration/org.eclipse.osgi/bundles/214/1/.cp/MathematicaSourceVersioned/Version6/MUnit
找到位置后,您可以使用以下命令查询 MUnit 包: (注意:路径很可能略有不同)
AppendTo[$Path,
FileNameJoin[{"/", "Applications", "Wolfram Workbench.app",
"configuration", "org.eclipse.osgi", "bundles", "214", "1", ".cp",
"MathematicaSourceVersioned", "Head", "MUnit"}]];
Needs["MUnit`"];
?MUnit`*
(* Need a blank line after ?MUnit`* otherwise a nasty message is generated. *)