Documentation/RunningTests

Not logged in - Log In / Register

Mago > Documentation > Running Tests

Running tests with Mago

Mago includes a test runner that will help you running your tests consistently and being able to present nice reports of your tests.

Mago test suites are arranged by application folder, XML test suites and each of the XML files contains one or more test cases. That allows us to be explicit on what to run each time: all the available mago tests, only several applications, only several tests suites or a couple of test cases.

Mago runner syntax

Usage: mago [options]

Execute automated tests

Options:
  -h, --help            show this help message and exit
  -i, --info            Display information about test cases without executing
                        them

  Test selection options:
    -a APPLICATION, --application=APPLICATION
                        Application name to test. Option can be repeated and
                        defaults to all applications
    -n NAME, --suite_name=NAME
                        Suite name to test within applications. Option can be
                        repeated and default to all suites unless suite name
                        or suite file filtering has been enabled
    -f FILE, --suite_file=FILE
                        Suite file to test within applications. Option can be
                        repeated and default to all suites unless suite name
                        or suite file filtering has been enabled
    -c CASE, --case=CASE
                        Test cases to run (all, if not specified).

  Logging options:
    -l FILE, --log=FILE
                        The file to write the log to.
    --log-level=LOG_LEVEL
                        One of debug, info, warning, error or critical.
    -t DIR, --target=DIR
                        Target directory for logs and reports. Defaults to:
                        ~/.mago

Skipping tests

There are some scenarios where you want a test case to be skipped during a run of tests. One of the main reasons for doing this is that a test case might be broken and there is not time to fix it. While fixing it you may want to skip it to avoid having wrong results.

Mago provides this feature through the <skip> tag in the XML test suite files.

This tag can be added to a whole test suite or a test case. Let's see how:

Skipping Test Suites

<suite name="gedit chains">
  
  <skip /> <!-- This will skip the whole test suite by default -->
  
  <class>gedit_chains.GEditChain</class>
  <description>
    Tests which verify gedit's save file functionality.
  </description>
  <case name="Unicode Tests">
    <method>testChain</method>
    <description>Test Unicode text saving.</description>
    <args>
      <oracle>data/utf8.txt</oracle>
      <chain>This is a Japanese string: 広告掲載 - ビジネス</chain>
    </args>
  </case>
  <case name="ASCII Test">
    <method>testChain</method>
    <description>Test ASCII text saving.</description>
    <args>
      <oracle>data/ascii.txt</oracle>
      <chain>This is a very basic string!</chain>
    </args>
  </case>
</suite>

By default, the skip tag at the test suite level would skip the whole test suite. There are cases were you would like to run it, although skipped by default. A common scenario for this would be when you're fixing a broken test suite. You NEED to run the tests to debug your changes.

If that test suite (the skipped one) is called to be run specifically in the command line, then, the <skip> tag would be ignored and the test suite would be run. Let's see some examples using the XML above:

Example 1

This will run all the test suites available, but it would skip the "gedit chains" test suite.

$ ./bin/mago

Example 2

This will run all the test suites available for the gedit application, but it would skip the "gedit chains" test suite.

$ ./bin/mago -a gedit

Example 3

This will run the gedit_chains test suite, because it was called explicitly.

$ ./bin/mago -f gedit_chains

Skipping Test Cases

<suite name="gedit chains"> 
  <class>gedit_chains.GEditChain</class>
  <description>
    Tests which verify gedit's save file functionality.
  </description>
  <case name="Unicode Tests">
    
    <skip /> <!-- This will skip the Unicode Tests test case by default -->
    
    <method>testChain</method>
    <description>Test Unicode text saving.</description>
    <args>
      <oracle>data/utf8.txt</oracle>
      <chain>This is a Japanese string: 広告掲載 - ビジネス</chain>
    </args>
  </case>
  <case name="ASCII Test">
    <method>testChain</method>
    <description>Test ASCII text saving.</description>
    <args>
      <oracle>data/ascii.txt</oracle>
      <chain>This is a very basic string!</chain>
    </args>
  </case>
</suite>

By default, the skip tag at the test case level would skip the test case it applies to.

As for test suites, if that test suite (the skipped one) is called to be run specifically in the command line, then, the <skip> tag would be ignored and the test case would be run. Let's see some examples using the XML above:

Example 1

This will run all the test suites available, but it would skip the "Unicode Tests" test case.

$ ./bin/mago

Example 2

This will run all the test suites available for the gedit application, but it would skip the "Unicode Tests" test case.

$ ./bin/mago -a gedit

Example 3

This will run all the test cases in the gedit_chains test suite, but it would skip the "Unicode Tests" test case.

$ ./bin/mago -f gedit_chains

Example 4

This will run the "Unicode Tests" test case, because it was called explicitly.

$ ./bin/mago -c "Unicode Tests"

Documentation/RunningTests (last edited 2010-11-17 11:14:07 by jibel)