Where is the location of MUnit in Wolfram Workbenc

2019-04-06 17:02发布

问题:

I have Mathematica 8.0 and Wolfram Workbench 2.0 for the Mac. I want to use MUnit to unit test a package I am creating, but I am finding the lack of documentation on MUnit to be frustrating.

The best resource so for has been Mathematic Cookbook by Sal Mangano. Section 19.11 covers "Integrating Wolfram Workbench’s MUnit Package into the Frontend".

I figure once I expose MUnit to the frontend, I will be able to query the MUnit API with ? . Just one problem, I can't find the MUnit package. I tried to locate the MUnit directory as suggested in the book with:

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

, but have not had any luck.

回答1:

If you up vote this answer, please show Szabolcs some luv by up voting his answer too. He was a tremendous help on this.

The location of MUnit is dependent upon the order that features of Wolfram Workbench were first used. That is just a theory, however it explains why find was not able to find MUnit initially, but finds it now. On my system MUnit is located at:

/Applications/Wolfram\ Workbench.app/configuration/org.eclipse.osgi/bundles/214/1/.cp/MathematicaSourceVersioned/Head/MUnit

To locate MUnit on your system using Wolfram Workbench:

  1. Create a test case that calls your code.
  2. Place a break point in your code that is tested by the test case.
  3. Debug the test case.
  4. Once you stop at the break point, keep stepping into the code and eventually you will step into Test.m when you step into TestID->"MyTest-20111230-L0X3S3".
  5. Hover the mouse over the Tab for Test.m and you will see the location of Test.m.

To locate MUnit on your system using find:

  1. Create a test case in Wolfram Workbench.
  2. Open terminal and type: find / -name MUnit -print 2> /dev/null

find results:

/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

Once you find the location you can query the MUnit package with: (note: the path most likely be slightly different)

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. *)


回答2:

I found MUnit.m in

...\configuration\org.eclipse.osgi\bundles\347\1\.cp\MathematicaSourceVersioned\Head\MUnit

within the Eclipse (or Workbench) installation directory. I don't have a Mac, but it should be in the same place regardless of platform.

There are also two other versions for Mathematica 6 and 5.2 (replace Head in the path with Version5.2 or Version6).



回答3:

As a supplement to the solutions presented by @Szabolcs and @mmorris, here is another way to determine the location of MUnit.m.

In the Wolfram Workbench, create an MUnit test that looks like this:

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

Run the test. It will fail, but the actual output of the test will be the desired pathname.