microservice teststrategie mit symfony2
TRANSCRIPT
Microservice-Teststrategiemit
Symfony2
ein Vortrag von Per Bernhardt
Mein Name ist Perhttp://perprogramming.de
Ich bin ein Chefkochhttp://www.chefkoch.de
Agenda• Worum geht es?
• Microservices
• Testarten
• Teststrategien
• Zusammenfassung
• Q & A
Worum geht es?
Erstmal vielen Dank an Toby Clemson!
http://martinfowler.com/articles/microservice-testing/
Microservices!
Microservices!
Teststrategie!
Microservices!
Teststrategie! ?
Microservices!
Teststrategie! ?!
Microservices!
Teststrategie! ?!
Microservices!
Teststrategie! ?!@
Microservices
A microservice architecture is […] the single responsibility principle
at the architectural level.„ “Quelle: http://martinfowler.com/articles/microservice-testing/#definition
App
BundleBundleBundle
App
BundleBundleBundle
AppBundle
AppBundle
AppBundle
@
@
Chefkoch
@
Chefkoch
Recipe User CMS
Video Blog Image
@
„
“
Quelle: http://martinfowler.com/articles/microservice-testing/#anatomy-modules
Symfony
Service Layer
Entities
Repositories
Doctrine ORM
Gat
eway
s
Guz
zle
Testarten
Unit Tests
Unit Tests
„“
Quelle: http://martinfowler.com/articles/microservice-testing/#testing-unit-diagram
Unit Tests
Unit Tests
Unit Tests
Unit Tests
Symfony
Service Layer
Entities
Repositories
Doctrine ORM
Gat
eway
s
Guz
zle
@
Unit Tests
Symfony
Service Layer
Entities
Repositories
Doctrine ORM
Gat
eway
s
Guz
zle
@
Unit Tests
Symfony
Service Layer
Entities
Repositories
Doctrine ORM
Gat
eway
s
Guz
zle
@
Unit Tests
Symfony
Service Layer
Entities
Repositories
Doctrine ORM
Gat
eway
s
Guz
zle
@
Unit Tests
Symfony
Service Layer
Entities
Repositories
Doctrine ORM
Gat
eway
s
Guz
zle
@
Unit Tests
Symfony
Service Layer
Entities
Repositories
Doctrine ORM
Gat
eway
s
Guz
zle
@
Unit Tests
Symfony
Service Layer
Entities
Repositories
Doctrine ORM
Gat
eway
s
Guz
zle
@
Unit Tests
Symfony
Service Layer
Entities
Repositories
Doctrine ORM
Gat
eway
s
Guz
zle
@
Unit Tests
Symfony
Service Layer
Entities
Repositories
Doctrine ORM
Gat
eway
s
Guz
zle
@
Unit Tests
Symfony
Service Layer
Entities
Repositories
Doctrine ORM
Gat
eway
s
Guz
zle
@
Unit Tests
Symfony
Service Layer
Entities
Repositories
Doctrine ORM
Gat
eway
s
Guz
zle
@
Integration Tests
Integration Tests
„“
Quelle: http://martinfowler.com/articles/microservice-testing/#testing-integration-diagram
<?php$config = Doctrine\ORM\Tools\Setup::createAnnotationMetadataConfiguration( '/path/to/config/files'); $entityManager = Doctrine\ORM\EntityManager::create( [ 'driver' => 'pdo_mysql', 'host' => 'localhost', 'user' => 'root', 'password' => '', 'dbname' => 'recipe' ], $config); $repository = $entityManager->getRepository( 'Chefkoch\Recipe\Domain\Model\Recipe');
@
<?php$config = Doctrine\ORM\Tools\Setup::createAnnotationMetadataConfiguration( '/path/to/config/files'); $entityManager = Doctrine\ORM\EntityManager::create( [ 'driver' => 'pdo_mysql', 'host' => 'localhost', 'user' => 'root', 'password' => '', 'dbname' => 'recipe' ], $config); $repository = $entityManager->getRepository( 'Chefkoch\Recipe\Domain\Model\Recipe');
@
Component Tests
Component Tests
„“
Quelle: http://martinfowler.com/articles/microservice-testing/#testing-component-in-process-diagram
Component Tests
Component Tests
Component Tests
WebTestCase!
Component Tests
WebTestCase!
SQLite
Component Tests
WebTestCase!
SQLite Mock Handler
<?phpnamespace Chefkoch\Bundle\RecipeBundle\Tests\Controller;use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;class RecipeStartpageControllerTest extends WebTestCase{ public function testRecipeStartpage() { $client = self::createClient(); $client->request('GET', '/rezepte'); $this->assertContains('Rezepte', $client->getResponse()->getContent()); }}
@
# config_test.ymldoctrine: dbal: driver: pdo_sqlite memory: true
<?phpnamespace Chefkoch\Bundle\RecipeBundle\Test\Controller;use Symfony\Bundle\FrameworkBundle\Test\WebTestCase as BaseWebTestCase;use Doctrine\ORM\EntityManager;use Doctrine\ORM\Tools\SchemaTool;abstract class WebTestCase extends BaseWebTestCase{ public function setUp() { $entityManager = self::getClient()->getContainer()->get( 'doctrine.orm.default_entity_manager' ); $schemaTool = new SchemaTool($entityManager); $schemaTool->createSchema( $entityManager->getMetadataFactory()->getAllMetadata() ); }}
<?phpuse GuzzleHttp\Client;use GuzzleHttp\Handler\MockHandler;use GuzzleHttp\HandlerStack;use GuzzleHttp\Psr7\Response;$mock = new MockHandler([ new Response( 200, ['Content-Type' => 'application/json'], '{"id": "1", "title": "Suppe"}' ) ]);$handler = HandlerStack::create($mock);$client = new Client( ['handler' => $handler] );
Component Tests
„“
Quelle: http://martinfowler.com/articles/microservice-testing/#testing-component-out-of-process-diagram
„Out of Process“
@
@var casper = require('casper').create();casper.test.begin('Teste Rezeptsuche', 2, function suite(test) { casper.start("http://api/v2/recipes", function() { test.assertHttpStatus(200); test.assertEquals(10, JSON.parse(this.getPageContent()).results.length); }); casper.run(function() { test.done(); });});
Contract Tests
Contract Tests
„“
Quelle: http://martinfowler.com/articles/microservice-testing/#testing-contract-diagram
End-To-End Tests
End-To-End Tests
„“
Quelle: http://martinfowler.com/articles/microservice-testing/#testing-end-to-end-diagram
@
@
@
@
/
@Feature: Admin Integration Als Salesmitarbeiter möchte ich das Wettbewerbsbackend über den normalen Admin verwenden können @mink:selenium2 Scenario: Login über Admin Given A sales user "admin" with password "tester" Given I am on "https://admin-local/rezeptwettbewerbe/admin" Then I should see "Benutzername:" When I fill in "Benutzername:" with "admin" When I fill in "Passwort:" with "tester" When I press "Einloggen!" Then I should see "Liste der Rezeptwettbewerbe" And I should see "Logout" And I should see "Hallo admin!"
Teststrategien
„“
Quelle: http://martinfowler.com/articles/microservice-testing/#conclusion-test-pyramid
„“
Quelle: http://martinfowler.com/articles/microservice-testing/#conclusion-options
Zusammenfassung
Zusammenfassung
„“
Quelle: http://martinfowler.com/articles/microservice-testing/#conclusion-summary
VielenDank !
?Fragenhttp://chefkoch.jobs - We are hiring ;)
http://perprogramming.de [email protected]