Upgrade to Pro — share decks privately, control downloads, hide ads and more …

A matter of trust – Test

A matter of trust – Test

Our daily work at Shopware, but also at agencies, ends up in the hands of people who trust us not only to have done our best, but also that it works. It is our job to instill this trust. Fortunately, we developers have a way to ensure something like that: Testing! Let's discover in this talk how we approach automated testing in Shopware, how far we have come on this journey, and what we have gained so far.

Ramona Schwering

June 19, 2020
Tweet

More Decks by Ramona Schwering

Other Decks in Programming

Transcript

  1. A matter of trust - Test

    View Slide

  2. Photo by Ankush Minda on Unsplash

    View Slide

  3. Photo by Luca Upper on Unsplash

    View Slide

  4. Photo by Bernard Hermant on Unsplash

    View Slide

  5. Testing
    @FloydThreepwood & @leichteckig

    View Slide

  6. Photo by freestocks on Unsplash

    View Slide

  7. Photo by Ferenc Almasi on Unsplash

    View Slide

  8. A test is a proof for your assumptions
    @FloydThreepwood & @leichteckig

    View Slide

  9. “Program testing can be used to show the
    presence of bugs, but never to show their
    absence!

    Edsger W. Dijkstra
    @FloydThreepwood & @leichteckig

    View Slide

  10. @FloydThreepwood & @leichteckig

    View Slide

  11. @FloydThreepwood & @leichteckig

    View Slide

  12. @FloydThreepwood & @leichteckig

    View Slide

  13. Service Tests
    @FloydThreepwood & @leichteckig

    View Slide

  14. Testing classes
    @FloydThreepwood & @leichteckig

    View Slide

  15. @FloydThreepwood & @leichteckig

    View Slide

  16. // Jest
    import 'src/module/sw-order/component/sw-order-user-card';
    describe('modules/sw-order/component/sw-order-user-card/tracking-code-display', () => {
    const userCard = Shopware.Component.build('sw-order-user-card');
    it('should render no url, when no base url is present in the shipping method', () => {
    expect(
    userCard.methods.renderTrackingUrl(
    'TR-4CK1N-GCD',
    {trackingUrl: ''}
    )
    ).toBe('');
    });
    });
    @FloydThreepwood & @leichteckig

    View Slide

  17. @FloydThreepwood & @leichteckig

    View Slide

  18. Integration tests
    @FloydThreepwood & @leichteckig

    View Slide

  19. Testing a stack
    @FloydThreepwood & @leichteckig

    View Slide

  20. @FloydThreepwood & @leichteckig

    View Slide

  21. //phpUnit
    namespace Shopware\Core\Checkout\Test\Order;
    class UserOrderTest extends PHPUnit\Framework\TestCase
    {
    use IntegrationTestBehaviour;
    public function testOrderFromNewUser(): void
    {
    $this->fillUpCart();
    $this->getContainer()->get(AccountService::class)
    ->register($newUserPayload);
    $this->getContainer()->get(CartService::class)
    ->order();
    $this->assertNewUserOrderedSuccessfully();
    }
    }
    @FloydThreepwood & @leichteckig

    View Slide

  22. @FloydThreepwood & @leichteckig

    View Slide

  23. End-to-end tests
    @FloydThreepwood & @leichteckig

    View Slide

  24. Real user workflows are simulated
    @FloydThreepwood & @leichteckig

    View Slide

  25. @FloydThreepwood & @leichteckig

    View Slide

  26. // Cypress
    describe('iphone-6 resolution', () => {
    // executed before each test
    beforeEach(() => {
    // run these tests as if in a mobile browser
    // and ensure our responsive UI is correct
    cy.viewport('iphone-6');
    });
    // actual test
    it('@navigation: Displays mobile menu on click', () => {
    cy.get('.nav.main-navigation-menu').should('not.be.visible');
    cy.get('.header-main .menu-button .nav-main-toggle-btn').should('be.visible').click();
    cy.get('.offcanvas.is-left.is-open').should('be.visible');
    });
    });
    @FloydThreepwood & @leichteckig

    View Slide

  27. Photo by Pankaj Patel on Unsplash

    View Slide

  28. Achievement unlocked!
    @FloydThreepwood & @leichteckig

    View Slide

  29. Photo by Kevin Butz on Unsplash

    View Slide

  30. Photo by Dave Lowe on Unsplash

    View Slide

  31. Challenges to face ...
    @FloydThreepwood & @leichteckig

    View Slide

  32. Photo by Veri Ivanova on Unsplash

    View Slide

  33. Photo by Annie Spratt on Unsplash

    View Slide

  34. TL;DR
    @FloydThreepwood & @leichteckig

    View Slide

  35. Photo by SpaceX on Unsplash

    View Slide

  36. Thank you!
    @FloydThreepwood & @leichteckig

    View Slide