Ce diaporama a bien été signalé.
Nous utilisons votre profil LinkedIn et vos données d’activité pour vous proposer des publicités personnalisées et pertinentes. Vous pouvez changer vos préférences de publicités à tout moment.
0Nicole Cordes, T3DD16 - Unit tests for dummies
Functional tests for dummies
» Introduction
» Basics
» Hands on
1Nicole Cordes, T3DD16 - Unit tests for dummies
Introduction
2Nicole Cordes, T3DD16 - Unit tests for dummies
INTRODUCTION
„Who is that girl?“
» Nicole Cordes
» working at CPS-IT GmbH ...
3Nicole Cordes, T3DD16 - Unit tests for dummies
Basics
4Nicole Cordes, T3DD16 - Unit tests for dummies
BASICS
„Why do I need functional tests?“
» test a part of your software
» ...
5Nicole Cordes, T3DD16 - Unit tests for dummies
BASICS
„What are you talking about?“
test case
test
test
test
test
asserti...
6Nicole Cordes, T3DD16 - Unit tests for dummies
BASICS
„What are you talking about?“
Processing of a test case
» find all ...
7Nicole Cordes, T3DD16 - Unit tests for dummies
BASICS
„What are you talking about?“
The life cycle of a test
» create an ...
8Nicole Cordes, T3DD16 - Unit tests for dummies
Hands on
9Nicole Cordes, T3DD16 - Unit tests for dummies
USE CASE
„ext_testing aka blog_example“
10Nicole Cordes, T3DD16 - Unit tests for dummies
RUNNING TESTS
„How to run tests from CLI?“
» clone TYPO3 core
» run `comp...
11Nicole Cordes, T3DD16 - Unit tests for dummies
RUNNING TESTS
„How to use an own MySQL instance?“
On Unix
» sudo mkdir /t...
12Nicole Cordes, T3DD16 - Unit tests for dummies
RUNNING TESTS
„How to use an own MySQL instance?“
On Windows (preparation...
13Nicole Cordes, T3DD16 - Unit tests for dummies
RUNNING TESTS
„How to use an own MySQL instance?“
On Windows (server hand...
18Nicole Cordes, T3DD16 - Unit tests for dummies
CODING FUNCTIONAL TESTS
„How does functional testing work?“
I
» set up yo...
19Nicole Cordes, T3DD16 - Unit tests for dummies
CODING FUNCTIONAL TESTS
„How does functional testing work?“
II
» move you...
20Nicole Cordes, T3DD16 - Unit tests for dummies
Thank you
for your attention!
Prochain SlideShare
Chargement dans…5
×

Functional tests for dummies

2 493 vues

Publié le

Session from TYPO3 Developer Days 2016

Publié dans : Internet
  • Soyez le premier à commenter

  • Soyez le premier à aimer ceci

Functional tests for dummies

  1. 1. 0Nicole Cordes, T3DD16 - Unit tests for dummies Functional tests for dummies » Introduction » Basics » Hands on
  2. 2. 1Nicole Cordes, T3DD16 - Unit tests for dummies Introduction
  3. 3. 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: typo3@cordes.co
  4. 4. 3Nicole Cordes, T3DD16 - Unit tests for dummies Basics
  5. 5. 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
  6. 6. 5Nicole Cordes, T3DD16 - Unit tests for dummies BASICS „What are you talking about?“ test case test test test test assertion assertion assertion
  7. 7. 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
  8. 8. 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
  9. 9. 8Nicole Cordes, T3DD16 - Unit tests for dummies Hands on
  10. 10. 9Nicole Cordes, T3DD16 - Unit tests for dummies USE CASE „ext_testing aka blog_example“
  11. 11. 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
  12. 12. 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
  13. 13. 12Nicole Cordes, T3DD16 - Unit tests for dummies RUNNING TESTS „How to use an own MySQL instance?“ On Windows (preparation) » copy "C:Program FilesMySQL Servermy.ini“ to "C:Program FilesMySQL Servermy-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/“
  14. 14. 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 FilesMySQL Serverbinmysqld.exe" --defaults-file="C:Program FilesMySQL Servermy-testing.ini“ » the server starts in the foreground (no new prompt appears until the server exits later) » stop the server with "C:Program FilesMySQL Serverbinmysqladmin.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_srcbinphpunit -c typo3/sysext/core/Build/FunctionalTests.xml”
  15. 15. 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
  16. 16. 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
  17. 17. 20Nicole Cordes, T3DD16 - Unit tests for dummies Thank you for your attention!

×