Book Image

Learning Yii Testing

Book Image

Learning Yii Testing

Overview of this book

Table of Contents (16 chapters)
Learning Yii Testing
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Implementing the first unit test


Yii provides an empty UserTest class for us, so we're going to start working from there. Head over to tests/codeception/unit/models/ and open the UserTest.php file.

So now our question is: what are we going to implement at this point? Well, the answer will be quite simple, once we've understood what the aim of the unit tests is.

Unit tests, as well as functional and acceptance tests, are a black box testing system: The tests will simply use the interface provided by the object and will make sure that the outputs are as expected. Since the implementation doesn't count if this changes slightly, or even radically, the tests should still pass assuming the interface remained the same.

White box testing, which is provided by code coverage, will instead ensure that we have covered all the possible branches of our code. We will discuss this further in Chapter 8, Analyzing Testing Information.

Tip

Unit tests also provide support for use cases that will document effectively...