Skip to content

tfrommen/unit-test-examples

master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
src
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

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