Home >php教程 >php手册 >Getting Started with Unit Testing SimpleTest

Getting Started with Unit Testing SimpleTest

WBOY
WBOYOriginal
2016-09-09 08:13:331901browse

I recently learned about unit testing. I first used PHPunit, but there were a lot of installation problems, so I immediately gave up and tried simpletest. It felt much easier. The steps are listed below.

1. Download simpletest (version 1.1.0), http://www.winsite.com/Development/Miscellaneous/SimpleTest/

Get a folder named simpletest

2. Place the folder in the root directory of your project.

3. Write the file to be tested, Sum.php, a simple sum class, and put it in the project root directory

4. Write the test file, testSum.php, and put it in the project root directory

We can see that there are 2 test classes and 5 test projects, and the test results of 2 of them are not in line with our expectations. When executing the test, there is no need to instantiate test classes 1 and 2, just execute the file directly .The results are as follows:

2/2 means there are 2 test classes; the results are 3 passed and 2 errors; the error reasons have been listed.

Let’s modify the code and correct the incorrect input:

The result is:

Test passed!

4. The above is just a simple example, the actual test must be much more complicated. Next is to read the document: https://pan.baidu.com/s/1nv0HOZv

5. Read the English documentation

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn