【问题标题】:Where is the location of MUnit in Wolfram Workbench 2.0 for the Mac?Mac 版 Wolfram Workbench 2.0 中 MUnit 的位置在哪里?
【发布时间】:2011-12-30 21:00:45
【问题描述】:

我有适用于 Mac 的 Mathematica 8.0 和 Wolfram Workbench 2.0。我想使用 MUnit 对我正在创建的包进行单元测试,但我发现缺乏关于 MUnit 的文档令人沮丧。

最好的资源是Mathematic Cookbook by Sal Mangano。第 19.11 节介绍“将 Wolfram Workbench 的 MUnit 包集成到前端”。

我认为一旦我将 MUnit 暴露给前端,我将能够使用 ? 查询 MUnit API .只有一个问题,我找不到 MUnit 包。我尝试按照书中的建议找到 MUnit 目录:

find / -name MUnit -print 2> /dev/null

,但没有运气。

【问题讨论】:

  • 只有在 Wolfram Workbench 中使用了 MUnit 包之后,对 find 的调用才有效。请参阅 Szabolcs 对已接受答案的评论。 请通过将他的评论投票给已接受的答案和他的答案来向 Szabolcs 展示一些爱。

标签: wolfram-mathematica


【解决方案1】:

如果您对这个答案投了赞成票,请也给 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:

  1. 创建一个调用您的代码的测试用例。
  2. 在测试用例测试的代码中放置一个断点。
  3. 调试测试用例。
  4. 一旦你停在断点处,继续单步执行代码,最终你会在单步到TestID->"MyTest-20111230-L0X3S3"时单步执行Test.m。
  5. 将鼠标悬停在 Test.m 的选项卡上,您将看到 Test.m 的位置。

使用 find 在您的系统上定位 MUnit:

  1. 在 Wolfram Workbench 中创建一个测试用例。
  2. 打开终端并输入: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. *)

【讨论】:

  • 我今天以更清晰的头脑再次查看了它,似乎在您使用 Workbench 本身的功能之前甚至没有提取这些文件。此外,路径在任何地方都不相同。为了让这个答案对大家有用,您能否详细解释一下您是如何找到路径的?
【解决方案2】:

我在

中找到MUnit.m
...\configuration\org.eclipse.osgi\bundles\347\1\.cp\MathematicaSourceVersioned\Head\MUnit

在 Eclipse(或 Workbench)安装目录中。我没有 Mac,但无论平台如何,它都应该在同一个地方。

Mathematica 6 和 5.2 还有两个其他版本(将路径中的 Head 替换为 Version5.2Version6)。

【讨论】:

  • 不幸的是不在 Mac 上。 ls /Applications/Wolfram\ Workbench.app/configuration/org.eclipse.osgi/bundles 100 124 132 147 158 171 176 180 207 211 215 42 69 96 112 125 133 154 161 172 177 187 209 213 216 54 84 123 126 135 157 163 175 179 188 210 214 29 66 91
  • @mmorris 好吧,您总是可以获取 Eclipse 版本(独立于平台)并从那里提取它。那是我检查的地方。我不知道这些数字是什么意思,也许你的在不同编号的目录中?
【解决方案3】:

作为对@Szabolcs 和@mmorris 提出的解决方案的补充,这里是另一种确定MUnit.m 位置的方法。

在 Wolfram Workbench 中,创建一个如下所示的 MUnit 测试:

Test[
  FindFile @ FileNameJoin @ {"MUnit", "MUnit.m"}
, ""
, TestID -> "FindMUnit-20120103-W7S3Q4"
]

运行测试。它会失败,但测试的实际输出将是所需的路径名。

【讨论】:

    猜你喜欢
    • 2011-12-05
    • 1970-01-01
    • 2019-09-11
    • 2011-04-17
    • 2023-03-14
    • 2016-02-24
    • 2018-02-23
    • 2016-05-16
    • 1970-01-01
    相关资源
    最近更新 更多