Skip to main content

Notice: this Wiki will be going read only early in 2024 and edits will no longer be possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.

Jump to: navigation, search

Orion/Running the tests

< Orion
Revision as of 18:36, 22 May 2014 by Mamacdon.gmail.com (Talk | contribs) (Running tests)

Client tests

Orion's client tests are written in JavaScript using the mocha test framework. Assertions are provided by the chai. The tests run in a web browser.

Organizing tests

  • Every source bundle in the Orion client repo (that is, every child folder of bundles/) should have exactly 1 test page. This makes it easy for developers to run all the bundle's tests in one shot.
  • Tests should be divided into files organized by functional components. Each component gets a separate file. (For example, the JavaScript bundle has separate test files dealing with JS content assist, JS validation, JS parsing, etc.)
  • All the tests artifacts for a bundle should go under the {bundle}/web/js-tests/ folder.

Running tests

  • To run all the tests for a bundle simply load its test page file in a web browser.
    • For example, the test page for the Web Tools bundle is webtoolsMochaTests.html. Therefore, to run the tests for the Web Tools bundle, you would navigate to http://[some_orion_server]/js-tests/webtools/webtoolsMochaTests.html.

Writing tests

First read Mocha: Getting Started for the basics of how tests are structured.

If you're adding tests to an existing file, [ TODO ]

To create a new test file, start with this skeleton: [ TODO ]

Now add your new test file to the parent bundle's test page. To do this, simply add a dependency in the require([ .. ]) call.

Writing tests

If you find yourself creating an entirely new bundle, then you'll have to create a test page. Start with this skeleton: [ TODO ]

Preparing a test page for the Orion build

To run a bundle's tests in the Orion build, you must perform the following steps:

  1. Important! Ensure that the test page loads the Sauce-enabled version of mocha defined in sauce.js.
    • To verify this, load your test page in a browser. You should see some XML output printed to the developer console: this means your test is Sauce-enabled. If you don't see a pile of XML, then your test page is wrong and will break the build.
  2. Open the package.json file and add your tests's URL to the urls array.

JVM Server tests

Setting up

  1. Set up your Eclipse IDE as explained in Orion/Getting the source.
  2. Make sure you have imported the test projects into your workspace, and they're open:
    • org.eclipse.orion.server.tests
    • org.eclipse.orion.server.tests.feature
  3. The test projects have additional dependencies over the rest of the Orion source code. The next 3 steps explain how to satisfy them.
  4. Add the plugins from your Eclipse SDK to your target platform:
    1. Go to Preferences > Target Platform, select your target definition and click Edit.
    2. Click Add... > Installation, then type ${eclipse_home} in the Location field.
    3. Click Finish.
    4. Now there should be 2 locations shown in your target definition. Click Finish.
      Orion-target-result.png
  5. Now we will checkout the remaining test dependencies from CVS. Download this file:
    File:OrionServerTestDepdendencies.psf.
  6. In your Eclipse IDE, go to File -> Import -> Team -> Team Project Set, select OrionServerTestDependencies.psf, and click Finish.
  7. At this point you should have no Java compilation errors. You can now run the tests.

Manually checking out the dependent projects

If the previous section fails for some reason, here's the list of projects from the .psf file. You can check them out manually if need be.

Projects from the Eclipse Platform CVS repository (/cvsroot/eclipse):

  • org.eclipse.core.runtime.compatibility
  • org.eclipse.core.runtime.compatibility.auth
  • org.eclipse.core.tests.harness
  • org.eclipse.core.tests.resources
  • org.eclipse.test.performance
  • org.eclipse.test.performance.data
  • org.eclipse.test.performance.win32

Projects from the Orbit CVS repository (/cvsroot/tools):

  • javax.mail.glassfish (Branch v1_4_1)
  • org.antlr.runtime (Branch v3_2_0)
  • org.hamcrest.core (Branch v1_1)
  • org.junit (Branch v3_8_2)
  • org.junit4 (Branch v4_8_2)

Running

  1. Go to the org.eclipse.orion.server.tests project.
  2. Open the launchConfigurations folder, right-click All Server Tests.launch and choose Run As > All Server Tests.
  3. The JUnit view will open and display the test results.

To run just a subset of the tests, edit the launch configuration (Run > Run Configurations).

Node.js Server Tests

Our Node server unit tests are written against the Mocha test framework.

Running the tests

From the org.eclipse.orion.client/modules/orionode directory, just run the command:

 npm test

This will invoke Mocha and produce console output showing which tests passed and failed.

If you want to pass custom arguments to Mocha, you'll need to invoke it explicitly like this:

 ./node_modules/mocha/bin/mocha [debug] [options] [files]

To make this easier, you can install Mocha as a global npm package (npm install mocha -g), and then invoke it as simply mocha from a command shell.

Writing more tests

When you're prototyping a new feature, writing unit tests for it is always a good idea. Here's how to write a test:

  1. Create a new file my_tests.js in the org.eclipse.orion.client/modules/orionode/test/ directory.
  2. Write your tests in the file. Here are two resources to help you get started:
  3. Run the tests.
    • You don't have to register your new tests with the framework; it will discover anything in the test/ directory automatically.

Helper data or classes should go in test/support/.

Back to the top