Running a PHPUnit Test Case

This procedure describes how to run a PHPUnit Test Case and how to analyze the results.

Before running a PHPUnit Test Case, one needs to be created by following the instructions under 'Creating a PHPUnit Test Case'.

 

 

Instructions on how to complete a procedure

To Run a PHPUnit Test Case:

  1. Open your PHPUnit Test Case file in the editor.

  2. To run the PHPUnit Test Case, click the arrow next to the Run  run_icon.png on the toolbar and select Run As | PHP Unit Test  phpunit_run_icon.png-or- from the Main Menu, go to Run and select Run As | PHP Unit Test phpunit_run_icon.png -or- right-click the file in PHP Explorer view and select Run As | PHP Unit Test.
    -Or- to debug the PPHUnit Test Case, click the arrow next to the debug button debug_icon.png on the toolbar and select Debug As | PHP Unit Test phpunit_run_icon.png-or- from the Main Menu, go to Run and select Debug As | PHP Unit Test phpunit_run_icon.png -or- right-click the file in PHP Explorer view and select Debug As | PHP Unit Test.
    The PHPUnit view will be displayed, with a section showing all the tests run and the results, and two extra tabbed views showing code coverage and failure trace.

PHPUnit View

  1. In the main area of the PHPUnit test view,  the results for each of the tests run will be displayed.
    Tests that have passed successfully will be displayed with a green tick icon. phpunit_successful_icon.png
    Tests that have failed will be displayed with a blue X icon. phpunit_failed_icon.png
    Functions with tests that have not been implemented (i.e. functions that tests have not been created for), will have passed but will have a note indicating that they have not been implemented.

  2. The number at the top of the view indicates how many tests have been run. Tests may not be run if an 'exit' command is given or if a fatal error is encountered.

  3. Click the 'Show failures only' iconphpunit_failures_only_icon.png  to only view failed results.

  4. Select a failed result to view it in the Failure Trace view. Click the Filter Stack Trace icon phpunit_failure_trace_filter.png to display only functions relevant to your application and not PHPUnit functions.

  5. Double-click on a failed result to be taken to the test function in the test file.
    To correct the failed result, either fix the test function or the original function on which it was run.

  6. The Code Coverage display indicates how much of the code in both the original file and the test file was run:

  • The  percentage in the Covered Lines column displays the percentage of lines executed out of the total number of executable lines.

  • The number of 'visited' lines are the number of executable code lines.

  • The number of 'significant' lines are the number of significant (i.e. executable) lines.

  • The number of 'total' lines is the total number of lines in the file.

  1. Click on the code coverage statistics next to each file to open the Code Coverage view displaying the code with the lines of code that were run.
    'Visited' lines will be highlighted in blue.
    'Significant' lines will be highlighted in pink.

Once you have corrected errors, you can re-run the PHPUnit Test by clicking the Run Last Test button phpunit_reruntest_icon.png in the PHPUnit view until all tests pass successfully.

 

 

Instructions on how to complete a procedure

To Debug a PHPUnit Test Case:

  1. Open your PHPUnit Test Case file in the editor.

  2. Click the arrow next to the Run button run_icon.png on the toolbar and select Run As | PHP Unit Test  phpunit_run_icon.png–or- from the Main Menu, go to Run and select Run As | PHP Unit Test phpunit_run_icon.png.
    -Or- to debug the PPHUnit Test Case, click the arrow next to the debug button debug_icon.png on the toolbar and select Debug As | PHP Unit Test  phpunit_run_icon.png–or- from the Main Menu, go to Run and select Debug As | PHP Unit Test phpunit_run_icon.png.
    The PHPUnit view will be displayed, with a section showing all the tests run and the results, and two extra tabbed views showing code coverage and failure trace.
     

PHPUnit View

  1. In the main area of the PHPUnit test view,  the results for each of the tests run will be displayed.
    Tests that have passed successfully will be displayed with a green tick icon. phpunit_successful_icon.png
    Tests that have failed will be displayed with a blue X icon. phpunit_failed_icon.png
    Functions with tests that have not been implemented (i.e. functions that tests have not been created for), will have passed but will have a note indicating that they have not been implemented.

  2. The number at the top of the view indicates how many tests have been run. Tests may not be run if an 'exit' command is given or if a fatal error is encountered.
  3. Click the 'Show failures only' iconphpunit_failures_only_icon.png  to only view failed results.

  4. Select a failed result to view it in the Failure Trace view. Click the Filter Stack Trace icon phpunit_failure_trace_filter.png to display only functions relevant to your application and not PHPUnit functions.

  5. Double-click on a failed result to be taken to the test function in the test file.
    To correct the failed result, either fix the test function or the original function on which it was run.

  6. The Code Coverage display indicates how much of the code in both the original file and the test file was run:

  • The  percentage in the Covered Lines column displays the percentage of lines executed out of the total number of executable lines.

  • The number of 'visited' lines are the number of executable code lines.

  • The number of 'significant' lines are the number of lines which were executed.

  • The number of 'total' lines is the total number of lines in the file.

  1. Click on the code coverage statistics next to each file to open the Code Coverage view displaying the code with the lines of code that were run.
    'Visited' lines will be highlighted in blue.
    'Significant' lines will be highlighted in pink.

Once you have corrected errors, you can re-run the PHPUnit Test by clicking the Run Last Test button phpunit_reruntest_icon.png in the PHPUnit view until all tests pass successfully.

You can transform the xml file created with while running the PHPUnit Teasr into an HTML report using the Report Generator icon phpunit_report_generator_icon.png . See Reporting on PHPUnit Test Results for more details.

 

 

link_icon.png

Related Links:

PHPUnit Testing

Working with PHPUnit Testing

Using PHPUnit Testing

Creating a PHPUnit Test Case

Creating a PHPUnit Test Suite

Running a PHPUnit Test Suite

Reporting on PHPUnit Test Results

PHPUnit Preferences