functional tests for dummies

17
Functional tests for dummies » Introduction » Basics » Hands on

Upload: cpsitgmbh

Post on 07-Jan-2017

174 views

Category:

Internet


0 download

TRANSCRIPT

Page 1: Functional tests for dummies

0Nicole Cordes, T3DD16 - Unit tests for dummies

Functional tests for dummies

» Introduction

» Basics

» Hands on

Page 2: Functional tests for dummies

1Nicole Cordes, T3DD16 - Unit tests for dummies

Introduction

Page 3: Functional tests for dummies

2Nicole Cordes, T3DD16 - Unit tests for dummies

INTRODUCTION„Who is that girl?“

» Nicole Cordes

» working at CPS-IT GmbH in Berlin

» community activity since 2011

» Core and Security Team member

» contributing to multiple public extensions

» Slack: @IchHabRecht

» Twitter: @IchHabRecht

» Mail: [email protected]

Page 4: Functional tests for dummies

3Nicole Cordes, T3DD16 - Unit tests for dummies

Basics

Page 5: Functional tests for dummies

4Nicole Cordes, T3DD16 - Unit tests for dummies

BASICS„Why do I need functional tests?“

» test a part of your software

» not about testing your functions or classes, but processes

» from a user's point of view

» for quality assurance (QA)

» unit tests don't ensure a correct workflow

» manual testing takes a lot of time

» encapsulated system (database) without site-effects or dependencies

Page 6: Functional tests for dummies

5Nicole Cordes, T3DD16 - Unit tests for dummies

BASICS„What are you talking about?“

test case

test

test

test

test

assertion

assertion

assertion

Page 7: Functional tests for dummies

6Nicole Cordes, T3DD16 - Unit tests for dummies

BASICS„What are you talking about?“

Processing of a test case

» find all tests within the class

» call one test after another

» test folder in typo3temp is created

» core is linked into test folder

» test extensions are linked into typo3conf/ext

» paths and files are linked

» LocalConfiguration.php is written

» PackageStates.php is written

» bootstrap is initialized

» database is created

» database scheme is imported

Page 8: Functional tests for dummies

7Nicole Cordes, T3DD16 - Unit tests for dummies

BASICS„What are you talking about?“

The life cycle of a test

» create an object of the test class

» call `setUp` method (protected!)

» objects and environment can be prepared

» call one test

» call `tearDown` method (protected!)

» objects and environment can be cleaned up

Page 9: Functional tests for dummies

8Nicole Cordes, T3DD16 - Unit tests for dummies

Hands on

Page 10: Functional tests for dummies

9Nicole Cordes, T3DD16 - Unit tests for dummies

USE CASE„ext_testing aka blog_example“

Page 11: Functional tests for dummies

10Nicole Cordes, T3DD16 - Unit tests for dummies

RUNNING TESTS„How to run tests from CLI?“

» clone TYPO3 core

» run `composer install`

» use the cloned core for your development

» run `typo3_src/bin/phpunit -c typo3/sysext/core/Build/FunctionalTests.xml typo3conf/ext/ext_testing`

» ! be aware that the functional tests dirty your database

Page 12: Functional tests for dummies

11Nicole Cordes, T3DD16 - Unit tests for dummies

RUNNING TESTS„How to use an own MySQL instance?“

On Unix

» sudo mkdir /tmp/mysqld-testing

» sudo chmod 700 /tmp/mysqld-testing

» sudo chown mysql:mysql /tmp/mysqld-testing

» sudo mysqld_safe --port=3307 --socket="/var/run/mysqld/mysqld-testing.sock" --user mysql --pid-

file="/var/run/mysqld/mysqld-testing.pid" --datadir="/tmp/mysqld-testing" --skip-grant-tables run

» typo3DatabaseHost="localhost" typo3DatabasePort=3307 typo3DatabaseName=“ext-testing" \

typo3DatabaseUsername=“root" typo3DatabasePassword="" \

typo3_src/bin/phpunit -c typo3/sysext/core/Build/FunctionalTests.xml

Page 13: Functional tests for dummies

12Nicole Cordes, T3DD16 - Unit tests for dummies

RUNNING TESTS„How to use an own MySQL instance?“

On Windows (preparation)

» copy "C:\Program Files\MySQL Server\my.ini“ to "C:\Program Files\MySQL Server\my-testing.ini“

» change “port=3306” to “port=3307” in [client] and [mysqld] section

» change datadir=“C:/ProgramData/MySQL/MySQL Server 5.5/data” to

datadir=“C:/ProgramData/MySQL/MySQL Server 5.5/data-testing”

» change innodb_data_home_dir="C:/ProgramData/MySQL InnoDB Datafiles/“ to

innodb_data_home_dir="C:/ProgramData/MySQL InnoDB Datafiles Testing/"

» create folder “C:/ProgramData/MySQL/MySQL Server 5.5/data-testing”

» copy mysql folder, ib_logfile0 and ib_logfile1 from original data folder

» copy "C:/ProgramData/MySQL InnoDB Datafiles/“ to "C:/ProgramData/MySQL InnoDB Datafiles Testing/“

Page 14: Functional tests for dummies

13Nicole Cordes, T3DD16 - Unit tests for dummies

RUNNING TESTS„How to use an own MySQL instance?“

On Windows (server handling)

» start server with "C:\Program Files\MySQL Server\bin\mysqld.exe" --defaults-file="C:\Program

Files\MySQL Server\my-testing.ini“

» the server starts in the foreground (no new prompt appears until the server exits later)

» stop the server with "C:\Program Files\MySQL Server\bin\mysqladmin.exe" -u root -p --port=3307

shutdown

» cmd /C “SET typo3DatabaseHost=localhost && SET typo3DatabasePort=3307 && \

SET typo3DatabaseName=ext-testing && SET typo3DatabaseUsername=root && \

SET typo3DatabasePassword= && \

typo3_src\bin\phpunit -c typo3/sysext/core/Build/FunctionalTests.xml”

Page 15: Functional tests for dummies

18Nicole Cordes, T3DD16 - Unit tests for dummies

CODING FUNCTIONAL TESTS„How does functional testing work?“

I

» set up your expectations

» define static requirements

» add a test case for your class

» implement requirements and test (decouple objects as much as you can)

» implement assertion

Page 16: Functional tests for dummies

19Nicole Cordes, T3DD16 - Unit tests for dummies

CODING FUNCTIONAL TESTS„How does functional testing work?“

II

» move your extension to GitHub

» set up the travis service in your repository settings

» add a composer.json file

» add .travis.yml

Page 17: Functional tests for dummies

20Nicole Cordes, T3DD16 - Unit tests for dummies

Thank youfor your attention!