Open topic with navigation
Running and Debugging a PHPUnit Test Case
This procedure describes how to run a PHPUnit Test Case in a file and on a single method within the file, 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.
Running a PHPUnit Test Case
|
|
|
To Run a PHPUnit Test Case:
-
Open your PHPUnit
Test Case file in the editor.
-
To run the PHPUnit
Test Case, click the arrow next to the Run
on the toolbar and select Run
As | PHP Unit Test -or-
from the Main Menu, go to Run and select Run
As | PHP Unit Test
-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
on the toolbar and select Debug
As | PHP Unit Test -or-
from the Main Menu, go to Run and select Debug
As | PHP Unit Test
-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.
-
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. Tests that have failed will be displayed with a blue X icon.
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.
-
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.
-
Click the 'Show
failures only' icon to
only view failed results.
-
Select a failed
result to view it in the Failure Trace view. Click the Filter
Stack Trace icon to display
only functions relevant to your application and not PHPUnit
functions.
-
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.
-
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.
-
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 in the PHPUnit
view until all tests pass successfully.
|
Running a Single PHPUnit Test Case
|
|
|
To Run a single PHPUnit Test Case on a method within the file:
-
Open your PHPUnit
Test Case file in the editor.
- Place your cursor on the method you wish to test, right-click and select
Run As | PHP Unit Test.
-
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. Tests that have failed will be displayed with a blue X icon.
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.
-
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.
-
Click the 'Show
failures only' icon to
only view failed results.
-
Select a failed
result to view it in the Failure Trace view. Click the Filter
Stack Trace icon to display
only functions relevant to your application and not PHPUnit
functions.
-
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.
-
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.
-
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 in the PHPUnit
view until all tests pass successfully.
Note:
Currently, debugging a single PHP test is not possible.
|
Debugging a PHPUnit Test Case
|
|
|
To Debug a PHPUnit Test Case:
-
Open your PHPUnit
Test Case file in the editor.
-
Click the arrow
next to the Run button
on the toolbar and select Run
As | PHP Unit Test –or-
from the Main Menu, go to Run and select Run
As | PHP Unit Test . -Or- to debug the PPHUnit Test Case, click the arrow next to
the debug button
on the toolbar and select Debug
As | PHP Unit Test –or-
from the Main Menu, go to Run 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.
-
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. Tests that have failed will be displayed with a blue X icon.
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.
- 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.
-
Click the 'Show
failures only' icon to
only view failed results.
-
Select a failed
result to view it in the Failure Trace view. Click the Filter
Stack Trace icon to display
only functions relevant to your application and not PHPUnit
functions.
-
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.
-
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.
-
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 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
. See Reporting on PHPUnit
Test Results for more details.
©1999-2013 Zend Technologies LTD. All rights reserved.