Skip to content

Example code for my talks and workshops on unit testing.

License

Notifications You must be signed in to change notification settings

tfrommen/unit-test-examples

Repository files navigation

Unit Test Examples

Example code for my talks and workshops on unit testing.

Getting Started

Clone this repository, or download the ZIP file.

There is both PHP and JavaScript example code waiting for you at src/php/ and src/js/, respectively.

Writing Tests

The repository is set up for you to write PHP tests with PHPUnit, and JavaScript tests with Jest. If you would rather use something else instead, feel free to adapt composer.json and package.json, respectively.

PHP Tests

In order to run the PHP tests, you have to install the required PHP packages first.

Install with Composer:

$ composer install

By default, this will install PHPUnit as well as Mockery, Patchwork and Brain Monkey.

Then, execute PHPUnit, which will use the configuration provided in phpunit.xml.dist:

$ ./vendor/bin/phpunit

JavaScript Tests

In order to run the JavaScript tests, you have to install the required JavaScript packages first.

Install with Yarn:

$ yarn

By default, this will install Jest (inlcuding jest-each), react-test-renderer and Enzyme (including enzyme-adapter-react-16), as well as the babel-preset-env and babel-preset-react packages.

Then, run the test script, defined in package.json:

$ yarn test

In case you want to use npm instead, do it like so:

$ npm i && npm run test

License

Copyright (c) 2018 Thorsten Frommen

This code is licensed under the MIT License.

About

Example code for my talks and workshops on unit testing.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published