{"id":3279,"date":"2024-10-18T15:45:01","date_gmt":"2024-10-18T07:45:01","guid":{"rendered":"https:\/\/www.openbyt.com\/?p=3279"},"modified":"2024-10-18T15:52:40","modified_gmt":"2024-10-18T07:52:40","slug":"how-to-implement-automated-testing-in-your-wordpress-workflow","status":"publish","type":"post","link":"https:\/\/www.openbyt.com\/de\/wie-sie-automatisierte-tests-in-ihren-wordpress-workflow-einbauen","title":{"rendered":"Wie Sie automatisierte Tests in Ihren WordPress-Workflow implementieren"},"content":{"rendered":"<div class=\"wp-block-group is-nowrap is-layout-flex wp-container-core-group-is-layout-ad2f72ca wp-block-group-is-layout-flex\"><p>Automatisierte Tests k\u00f6nnen sich f\u00fcr WordPress-Entwickler entmutigend anf\u00fchlen, vor allem, wenn Sie sich noch nie damit besch\u00e4ftigt haben. Stellen Sie sich vor, Sie h\u00e4tten ein Sicherheitsnetz, wenn Sie sich auf einem Drahtseil bewegen - wenn es einmal installiert ist, ist sichergestellt, dass Sie gesch\u00fctzt sind, selbst wenn etwas schief geht. Genauso wie ein Sicherheitsnetz Fehler auff\u00e4ngt, fangen automatisierte Tests Fehler ab, bevor sie in die Produktion gelangen. Aber in einer Welt der Entwicklung, in der Stabilit\u00e4t, Effizienz und Skalierbarkeit einen hohen Stellenwert haben, sind automatisierte Tests eines der effektivsten Werkzeuge, die Sie einsetzen k\u00f6nnen, um Ihre Arbeitsabl\u00e4ufe zu optimieren. Dieser Leitfaden richtet sich an WordPress-Entwickler, die ihren Qualit\u00e4tssicherungsprozess verbessern und sich beruflich weiterentwickeln m\u00f6chten. Ich f\u00fchre Sie durch die Einrichtung von automatisierten Tests, komplett mit Codebeispielen und praktischen Erkl\u00e4rungen.<\/p><\/div><figure class=\"wp-block-image size-full\"><img fetchpriority=\"high\" decoding=\"async\" width=\"1024\" height=\"1024\" src=\"https:\/\/www.openbyt.com\/wp-content\/uploads\/2024\/10\/DALL\u00b7E-2024-10-18-14.34.00-A-WordPress-developer-walking-a-tightrope-with-a-supportive-visible-safety-net-below-labeled-Automated-Testing.-The-developer-is-holding-a-laptop-d.webp\" alt=\"\" class=\"wp-image-3299\" srcset=\"https:\/\/www.openbyt.com\/wp-content\/uploads\/2024\/10\/DALL\u00b7E-2024-10-18-14.34.00-A-WordPress-developer-walking-a-tightrope-with-a-supportive-visible-safety-net-below-labeled-Automated-Testing.-The-developer-is-holding-a-laptop-d.webp 1024w, https:\/\/www.openbyt.com\/wp-content\/uploads\/2024\/10\/DALL\u00b7E-2024-10-18-14.34.00-A-WordPress-developer-walking-a-tightrope-with-a-supportive-visible-safety-net-below-labeled-Automated-Testing.-The-developer-is-holding-a-laptop-d-600x600.webp 600w, https:\/\/www.openbyt.com\/wp-content\/uploads\/2024\/10\/DALL\u00b7E-2024-10-18-14.34.00-A-WordPress-developer-walking-a-tightrope-with-a-supportive-visible-safety-net-below-labeled-Automated-Testing.-The-developer-is-holding-a-laptop-d-100x100.webp 100w, https:\/\/www.openbyt.com\/wp-content\/uploads\/2024\/10\/DALL\u00b7E-2024-10-18-14.34.00-A-WordPress-developer-walking-a-tightrope-with-a-supportive-visible-safety-net-below-labeled-Automated-Testing.-The-developer-is-holding-a-laptop-d-300x300.webp 300w, https:\/\/www.openbyt.com\/wp-content\/uploads\/2024\/10\/DALL\u00b7E-2024-10-18-14.34.00-A-WordPress-developer-walking-a-tightrope-with-a-supportive-visible-safety-net-below-labeled-Automated-Testing.-The-developer-is-holding-a-laptop-d-150x150.webp 150w, https:\/\/www.openbyt.com\/wp-content\/uploads\/2024\/10\/DALL\u00b7E-2024-10-18-14.34.00-A-WordPress-developer-walking-a-tightrope-with-a-supportive-visible-safety-net-below-labeled-Automated-Testing.-The-developer-is-holding-a-laptop-d-768x768.webp 768w, https:\/\/www.openbyt.com\/wp-content\/uploads\/2024\/10\/DALL\u00b7E-2024-10-18-14.34.00-A-WordPress-developer-walking-a-tightrope-with-a-supportive-visible-safety-net-below-labeled-Automated-Testing.-The-developer-is-holding-a-laptop-d-12x12.webp 12w, https:\/\/www.openbyt.com\/wp-content\/uploads\/2024\/10\/DALL\u00b7E-2024-10-18-14.34.00-A-WordPress-developer-walking-a-tightrope-with-a-supportive-visible-safety-net-below-labeled-Automated-Testing.-The-developer-is-holding-a-laptop-d-96x96.webp 96w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure><h3 class=\"wp-block-heading\">Was ist automatisiertes Testen?<\/h3><p>Vereinfacht ausgedr\u00fcckt ist das automatisierte Testen eine M\u00f6glichkeit, um sicherzustellen, dass der von Ihnen geschriebene Code wie vorgesehen funktioniert, ohne dass Sie jede Funktion manuell \u00fcberpr\u00fcfen m\u00fcssen. Es geht darum, Skripte auszuf\u00fchren, die verschiedene Aspekte Ihrer Anwendung \u00fcberpr\u00fcfen. Funktioniert dieses Plugin auch nach dem letzten Update noch? Wird die Theme-Anpassung noch richtig wiedergegeben? Automatisierte Tests helfen dabei, potenzielle Probleme bereits in einem fr\u00fchen Stadium der Entwicklung zu erkennen, was Ihnen unz\u00e4hlige Stunden f\u00fcr die Fehlerbehebung und das Debugging erspart.<\/p><p>Automatisierte Tests f\u00fcr WordPress k\u00f6nnen Unit-Tests, Integrationstests und sogar End-to-End-Tests umfassen, um alles abzudecken, von kleinen Teilen der Logik bis zu vollst\u00e4ndig gerenderten Seiten. Schauen wir uns die Integration von automatisierten Tests in einen WordPress-Entwicklungsworkflow an.<\/p><figure class=\"wp-block-image size-full\"><img decoding=\"async\" width=\"1024\" height=\"1024\" src=\"https:\/\/www.openbyt.com\/wp-content\/uploads\/2024\/10\/DALL\u00b7E-2024-10-18-14.30.53-A-developer-working-with-automated-testing-tools-for-WordPress.-The-developer-is-sitting-at-a-desk-surrounded-by-screens-showing-PHPUnit-Cypress-and.webp\" alt=\"\" class=\"wp-image-3300\" srcset=\"https:\/\/www.openbyt.com\/wp-content\/uploads\/2024\/10\/DALL\u00b7E-2024-10-18-14.30.53-A-developer-working-with-automated-testing-tools-for-WordPress.-The-developer-is-sitting-at-a-desk-surrounded-by-screens-showing-PHPUnit-Cypress-and.webp 1024w, https:\/\/www.openbyt.com\/wp-content\/uploads\/2024\/10\/DALL\u00b7E-2024-10-18-14.30.53-A-developer-working-with-automated-testing-tools-for-WordPress.-The-developer-is-sitting-at-a-desk-surrounded-by-screens-showing-PHPUnit-Cypress-and-600x600.webp 600w, https:\/\/www.openbyt.com\/wp-content\/uploads\/2024\/10\/DALL\u00b7E-2024-10-18-14.30.53-A-developer-working-with-automated-testing-tools-for-WordPress.-The-developer-is-sitting-at-a-desk-surrounded-by-screens-showing-PHPUnit-Cypress-and-100x100.webp 100w, https:\/\/www.openbyt.com\/wp-content\/uploads\/2024\/10\/DALL\u00b7E-2024-10-18-14.30.53-A-developer-working-with-automated-testing-tools-for-WordPress.-The-developer-is-sitting-at-a-desk-surrounded-by-screens-showing-PHPUnit-Cypress-and-300x300.webp 300w, https:\/\/www.openbyt.com\/wp-content\/uploads\/2024\/10\/DALL\u00b7E-2024-10-18-14.30.53-A-developer-working-with-automated-testing-tools-for-WordPress.-The-developer-is-sitting-at-a-desk-surrounded-by-screens-showing-PHPUnit-Cypress-and-150x150.webp 150w, https:\/\/www.openbyt.com\/wp-content\/uploads\/2024\/10\/DALL\u00b7E-2024-10-18-14.30.53-A-developer-working-with-automated-testing-tools-for-WordPress.-The-developer-is-sitting-at-a-desk-surrounded-by-screens-showing-PHPUnit-Cypress-and-768x768.webp 768w, https:\/\/www.openbyt.com\/wp-content\/uploads\/2024\/10\/DALL\u00b7E-2024-10-18-14.30.53-A-developer-working-with-automated-testing-tools-for-WordPress.-The-developer-is-sitting-at-a-desk-surrounded-by-screens-showing-PHPUnit-Cypress-and-12x12.webp 12w, https:\/\/www.openbyt.com\/wp-content\/uploads\/2024\/10\/DALL\u00b7E-2024-10-18-14.30.53-A-developer-working-with-automated-testing-tools-for-WordPress.-The-developer-is-sitting-at-a-desk-surrounded-by-screens-showing-PHPUnit-Cypress-and-96x96.webp 96w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure><h3 class=\"wp-block-heading\">Einrichten Ihrer Umgebung<\/h3><p>Zun\u00e4chst brauchen Sie die richtige Umgebung, um loszulegen. PHPUnit ist eine ausgezeichnete Wahl f\u00fcr WordPress, denn es wurde speziell f\u00fcr das Testen von PHP-Code entwickelt, der den Kern von WordPress-Plugins und Themes ausmacht. Es erm\u00f6glicht Entwicklern, einzelne Funktionen zu isolieren und ihr Verhalten in einer kontrollierten Umgebung zu \u00fcberpr\u00fcfen, was besonders n\u00fctzlich ist, um Fehler in einem fr\u00fchen Stadium der Entwicklung zu erkennen. Ein beliebtes Tool f\u00fcr die Durchf\u00fchrung automatisierter Tests in einer WordPress-Umgebung ist <strong>PHPUnit<\/strong>. PHPUnit eignet sich perfekt f\u00fcr Unit-Tests von PHP-Code - eine wichtige Komponente von WordPress-Plugins und Themes. Hier ist, was Sie einrichten m\u00fcssen:<\/p><ul class=\"wp-block-list\"><li><strong>PHPUnit installieren<\/strong>: Stellen Sie sicher, dass Sie Composer auf Ihrem System installiert haben, da PHPUnit \u00fcber Composer installiert wird. Sie k\u00f6nnen den folgenden Befehl verwenden, um es zu installieren:<\/li><\/ul><p>                 <code>composer require --dev phpunit\/phpunit<\/code><\/p><ul class=\"wp-block-list\"><li><strong>Einrichten der WordPress Testing Suite<\/strong>: Laden Sie die WordPress-Testbibliothek herunter und konfigurieren Sie sie. Dies ist eine vereinfachte Version, da wir davon ausgehen, dass Sie diese lokal einrichten:<\/li><\/ul><p>                 <code>bash bin\/install-wp-tests.sh wordpress_test_dbroot 'Passwort' localhost latest<\/code><\/p><figure class=\"wp-block-image size-full\"><img decoding=\"async\" width=\"1024\" height=\"1024\" src=\"https:\/\/www.openbyt.com\/wp-content\/uploads\/2024\/10\/02c4875e-fbbf-4783-8aae-adbb23947c4f.webp\" alt=\"\" class=\"wp-image-3306\" srcset=\"https:\/\/www.openbyt.com\/wp-content\/uploads\/2024\/10\/02c4875e-fbbf-4783-8aae-adbb23947c4f.webp 1024w, https:\/\/www.openbyt.com\/wp-content\/uploads\/2024\/10\/02c4875e-fbbf-4783-8aae-adbb23947c4f-600x600.webp 600w, https:\/\/www.openbyt.com\/wp-content\/uploads\/2024\/10\/02c4875e-fbbf-4783-8aae-adbb23947c4f-100x100.webp 100w, https:\/\/www.openbyt.com\/wp-content\/uploads\/2024\/10\/02c4875e-fbbf-4783-8aae-adbb23947c4f-300x300.webp 300w, https:\/\/www.openbyt.com\/wp-content\/uploads\/2024\/10\/02c4875e-fbbf-4783-8aae-adbb23947c4f-150x150.webp 150w, https:\/\/www.openbyt.com\/wp-content\/uploads\/2024\/10\/02c4875e-fbbf-4783-8aae-adbb23947c4f-768x768.webp 768w, https:\/\/www.openbyt.com\/wp-content\/uploads\/2024\/10\/02c4875e-fbbf-4783-8aae-adbb23947c4f-12x12.webp 12w, https:\/\/www.openbyt.com\/wp-content\/uploads\/2024\/10\/02c4875e-fbbf-4783-8aae-adbb23947c4f-96x96.webp 96w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure><p>Ersetzen Sie die Platzhalter durch Ihre tats\u00e4chlichen Datenbankanmeldeinformationen. Um die Sicherheit zu erh\u00f6hen, sollten Sie vermeiden, sensible Informationen direkt in Ihren Skripten zu kodieren. Verwenden Sie stattdessen Umgebungsvariablen oder eine sichere Konfigurationsdatei, die von der Versionskontrolle nicht verfolgt wird.<\/p><h3 class=\"wp-block-heading\">Einen einfachen Unit-Test schreiben<\/h3><p>Lassen Sie uns einen einfachen Unit-Test f\u00fcr eine benutzerdefinierte Funktion erstellen. Unit-Tests dienen dazu, zu \u00fcberpr\u00fcfen, ob einzelne Teile des Codes, z.B. Funktionen oder Methoden, isoliert korrekt funktionieren. Sie bilden die Grundlage f\u00fcr automatisierte Tests und unterscheiden sich von Integrationstests, die sicherstellen, dass mehrere Komponenten zusammen funktionieren, und von End-to-End-Tests, die den gesamten Ablauf einer Anwendung von Anfang bis Ende testen. Nehmen wir an, Sie haben eine Funktion calculate_discount() in Ihrem Plugin:<\/p><figure class=\"wp-block-image size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"494\" src=\"https:\/\/www.openbyt.com\/wp-content\/uploads\/2024\/10\/screenshot-1024x494.png\" alt=\"\" class=\"wp-image-3303\" style=\"width:839px;height:auto\" srcset=\"https:\/\/www.openbyt.com\/wp-content\/uploads\/2024\/10\/screenshot-1024x494.png 1024w, https:\/\/www.openbyt.com\/wp-content\/uploads\/2024\/10\/screenshot-600x289.png 600w, https:\/\/www.openbyt.com\/wp-content\/uploads\/2024\/10\/screenshot-300x145.png 300w, https:\/\/www.openbyt.com\/wp-content\/uploads\/2024\/10\/screenshot-768x370.png 768w, https:\/\/www.openbyt.com\/wp-content\/uploads\/2024\/10\/screenshot-1536x741.png 1536w, https:\/\/www.openbyt.com\/wp-content\/uploads\/2024\/10\/screenshot-2048x988.png 2048w, https:\/\/www.openbyt.com\/wp-content\/uploads\/2024\/10\/screenshot-18x9.png 18w, https:\/\/www.openbyt.com\/wp-content\/uploads\/2024\/10\/screenshot-150x72.png 150w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure><p>Um einen Unit-Test f\u00fcr diese Funktion zu schreiben, m\u00fcssen Sie eine neue Testdatei in Ihrem tests-Ordner erstellen. Hier ist ein Beispiel:<\/p><pre class=\"wp-block-code\"><code>\/\/ Datei: mein-plugin\/tests\/test-functions.php\nPHPUnit\\Framework\\TestCase verwenden;\n\nclass FunctionsTest erweitert TestCase {\n    public function test_berechnen_Rabatt() {\n        require_once dirname(__FILE__) . '\/..\/includes\/functions.php';\n\n        $result = berechne_Rabatt(100, 20);\n        $this-&gt;assertEquals(80, $result, '20% Rabatt auf $100 sollte $80 ergeben');\n    }\n\n    public function test_ung\u00fcltiger_Rabatt() {\n        $this-&gt;expectException(InvalidArgumentException::class);\n        berechne_rabatt(100, -10);\n    }\n}<\/code><\/pre><h3 class=\"wp-block-heading\">Laufende Tests<\/h3><p>Sobald Sie den Test geschrieben haben, k\u00f6nnen Sie ihn mit dem folgenden Befehl ausf\u00fchren:<\/p><p><code>vendor\/bin\/phpunit<\/code><\/p><figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"1024\" src=\"https:\/\/www.openbyt.com\/wp-content\/uploads\/2024\/10\/DALL\u00b7E-2024-10-18-15.20.52-An-illustration-of-a-developer-sitting-at-a-desk-working-on-writing-unit-tests-for-a-WordPress-plugin.-The-developers-screen-shows-code-similar-to-P.webp\" alt=\"\" class=\"wp-image-3308\" srcset=\"https:\/\/www.openbyt.com\/wp-content\/uploads\/2024\/10\/DALL\u00b7E-2024-10-18-15.20.52-An-illustration-of-a-developer-sitting-at-a-desk-working-on-writing-unit-tests-for-a-WordPress-plugin.-The-developers-screen-shows-code-similar-to-P.webp 1024w, https:\/\/www.openbyt.com\/wp-content\/uploads\/2024\/10\/DALL\u00b7E-2024-10-18-15.20.52-An-illustration-of-a-developer-sitting-at-a-desk-working-on-writing-unit-tests-for-a-WordPress-plugin.-The-developers-screen-shows-code-similar-to-P-600x600.webp 600w, https:\/\/www.openbyt.com\/wp-content\/uploads\/2024\/10\/DALL\u00b7E-2024-10-18-15.20.52-An-illustration-of-a-developer-sitting-at-a-desk-working-on-writing-unit-tests-for-a-WordPress-plugin.-The-developers-screen-shows-code-similar-to-P-100x100.webp 100w, https:\/\/www.openbyt.com\/wp-content\/uploads\/2024\/10\/DALL\u00b7E-2024-10-18-15.20.52-An-illustration-of-a-developer-sitting-at-a-desk-working-on-writing-unit-tests-for-a-WordPress-plugin.-The-developers-screen-shows-code-similar-to-P-300x300.webp 300w, https:\/\/www.openbyt.com\/wp-content\/uploads\/2024\/10\/DALL\u00b7E-2024-10-18-15.20.52-An-illustration-of-a-developer-sitting-at-a-desk-working-on-writing-unit-tests-for-a-WordPress-plugin.-The-developers-screen-shows-code-similar-to-P-150x150.webp 150w, https:\/\/www.openbyt.com\/wp-content\/uploads\/2024\/10\/DALL\u00b7E-2024-10-18-15.20.52-An-illustration-of-a-developer-sitting-at-a-desk-working-on-writing-unit-tests-for-a-WordPress-plugin.-The-developers-screen-shows-code-similar-to-P-768x768.webp 768w, https:\/\/www.openbyt.com\/wp-content\/uploads\/2024\/10\/DALL\u00b7E-2024-10-18-15.20.52-An-illustration-of-a-developer-sitting-at-a-desk-working-on-writing-unit-tests-for-a-WordPress-plugin.-The-developers-screen-shows-code-similar-to-P-12x12.webp 12w, https:\/\/www.openbyt.com\/wp-content\/uploads\/2024\/10\/DALL\u00b7E-2024-10-18-15.20.52-An-illustration-of-a-developer-sitting-at-a-desk-working-on-writing-unit-tests-for-a-WordPress-plugin.-The-developers-screen-shows-code-similar-to-P-96x96.webp 96w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure><h3 class=\"wp-block-heading\">End-to-End-Tests mit Cypress<\/h3><p>Unit-Tests sind ein fantastischer Ausgangspunkt, aber bei komplexen WordPress-Websites sollten Sie auch die gesamte Funktionalit\u00e4t der Website \u00fcberpr\u00fcfen. Unit-Tests konzentrieren sich darauf, einzelne Komponenten isoliert zu testen, w\u00e4hrend Integrationstests sicherstellen, dass verschiedene Module wie erwartet zusammenarbeiten. End-to-End-Tests hingegen simulieren echte Benutzerszenarien, um zu \u00fcberpr\u00fcfen, ob das gesamte System wie vorgesehen funktioniert, vom Backend bis zur Benutzeroberfl\u00e4che. Das ist der Punkt <strong>Zypresse<\/strong> kommt herein. Cypress ist ein JavaScript-basiertes End-to-End-Testing-Tool, das gut mit WordPress zusammenarbeitet und Ihnen die programmatische Interaktion mit der eigentlichen Weboberfl\u00e4che erm\u00f6glicht.<\/p><figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"1024\" src=\"https:\/\/www.openbyt.com\/wp-content\/uploads\/2024\/10\/DALL\u00b7E-2024-10-18-15.25.58-An-illustration-of-a-WordPress-testing-process-showing-unit-testing-integration-testing-and-end-to-end-testing.-The-scene-depicts-a-developer-surro.webp\" alt=\"\" class=\"wp-image-3309\" srcset=\"https:\/\/www.openbyt.com\/wp-content\/uploads\/2024\/10\/DALL\u00b7E-2024-10-18-15.25.58-An-illustration-of-a-WordPress-testing-process-showing-unit-testing-integration-testing-and-end-to-end-testing.-The-scene-depicts-a-developer-surro.webp 1024w, https:\/\/www.openbyt.com\/wp-content\/uploads\/2024\/10\/DALL\u00b7E-2024-10-18-15.25.58-An-illustration-of-a-WordPress-testing-process-showing-unit-testing-integration-testing-and-end-to-end-testing.-The-scene-depicts-a-developer-surro-600x600.webp 600w, https:\/\/www.openbyt.com\/wp-content\/uploads\/2024\/10\/DALL\u00b7E-2024-10-18-15.25.58-An-illustration-of-a-WordPress-testing-process-showing-unit-testing-integration-testing-and-end-to-end-testing.-The-scene-depicts-a-developer-surro-100x100.webp 100w, https:\/\/www.openbyt.com\/wp-content\/uploads\/2024\/10\/DALL\u00b7E-2024-10-18-15.25.58-An-illustration-of-a-WordPress-testing-process-showing-unit-testing-integration-testing-and-end-to-end-testing.-The-scene-depicts-a-developer-surro-300x300.webp 300w, https:\/\/www.openbyt.com\/wp-content\/uploads\/2024\/10\/DALL\u00b7E-2024-10-18-15.25.58-An-illustration-of-a-WordPress-testing-process-showing-unit-testing-integration-testing-and-end-to-end-testing.-The-scene-depicts-a-developer-surro-150x150.webp 150w, https:\/\/www.openbyt.com\/wp-content\/uploads\/2024\/10\/DALL\u00b7E-2024-10-18-15.25.58-An-illustration-of-a-WordPress-testing-process-showing-unit-testing-integration-testing-and-end-to-end-testing.-The-scene-depicts-a-developer-surro-768x768.webp 768w, https:\/\/www.openbyt.com\/wp-content\/uploads\/2024\/10\/DALL\u00b7E-2024-10-18-15.25.58-An-illustration-of-a-WordPress-testing-process-showing-unit-testing-integration-testing-and-end-to-end-testing.-The-scene-depicts-a-developer-surro-12x12.webp 12w, https:\/\/www.openbyt.com\/wp-content\/uploads\/2024\/10\/DALL\u00b7E-2024-10-18-15.25.58-An-illustration-of-a-WordPress-testing-process-showing-unit-testing-integration-testing-and-end-to-end-testing.-The-scene-depicts-a-developer-surro-96x96.webp 96w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure><p>F\u00fcgen Sie zun\u00e4chst Cypress zu Ihrer Entwicklungsumgebung hinzu:<\/p><p><code>npm install cypress --save-dev<\/code><\/p><p>Als n\u00e4chstes erstellen Sie einen einfachen Cypress-Test, der \u00fcberpr\u00fcft, ob Ihre WordPress-Homepage korrekt geladen wird:<\/p><pre class=\"wp-block-code\"><code>\/\/ Datei: cypress\/integration\/homepage.spec.js\ndescribe('WordPress Homepage', () =&gt; {\n    it('soll die Homepage laden', () =&gt; {\n        cy.visit('http:\/\/localhost:8000');\n        cy.contains('Willkommen bei WordPress').should('be.visible');\n    });\n});<\/code><\/pre><p>F\u00fchren Sie Cypress mit aus:<\/p><p><code>npx zypresse offen<\/code><\/p><h3 class=\"wp-block-heading\">Integration von Tests in Ihre CI\/CD-Pipeline<\/h3><figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"1024\" src=\"https:\/\/www.openbyt.com\/wp-content\/uploads\/2024\/10\/DALL\u00b7E-2024-10-18-15.25.58-An-illustration-of-a-WordPress-testing-process-showing-unit-testing-integration-testing-and-end-to-end-testing.-The-scene-depicts-a-developer-surro-1.webp\" alt=\"\" class=\"wp-image-3311\" srcset=\"https:\/\/www.openbyt.com\/wp-content\/uploads\/2024\/10\/DALL\u00b7E-2024-10-18-15.25.58-An-illustration-of-a-WordPress-testing-process-showing-unit-testing-integration-testing-and-end-to-end-testing.-The-scene-depicts-a-developer-surro-1.webp 1024w, https:\/\/www.openbyt.com\/wp-content\/uploads\/2024\/10\/DALL\u00b7E-2024-10-18-15.25.58-An-illustration-of-a-WordPress-testing-process-showing-unit-testing-integration-testing-and-end-to-end-testing.-The-scene-depicts-a-developer-surro-1-600x600.webp 600w, https:\/\/www.openbyt.com\/wp-content\/uploads\/2024\/10\/DALL\u00b7E-2024-10-18-15.25.58-An-illustration-of-a-WordPress-testing-process-showing-unit-testing-integration-testing-and-end-to-end-testing.-The-scene-depicts-a-developer-surro-1-100x100.webp 100w, https:\/\/www.openbyt.com\/wp-content\/uploads\/2024\/10\/DALL\u00b7E-2024-10-18-15.25.58-An-illustration-of-a-WordPress-testing-process-showing-unit-testing-integration-testing-and-end-to-end-testing.-The-scene-depicts-a-developer-surro-1-300x300.webp 300w, https:\/\/www.openbyt.com\/wp-content\/uploads\/2024\/10\/DALL\u00b7E-2024-10-18-15.25.58-An-illustration-of-a-WordPress-testing-process-showing-unit-testing-integration-testing-and-end-to-end-testing.-The-scene-depicts-a-developer-surro-1-150x150.webp 150w, https:\/\/www.openbyt.com\/wp-content\/uploads\/2024\/10\/DALL\u00b7E-2024-10-18-15.25.58-An-illustration-of-a-WordPress-testing-process-showing-unit-testing-integration-testing-and-end-to-end-testing.-The-scene-depicts-a-developer-surro-1-768x768.webp 768w, https:\/\/www.openbyt.com\/wp-content\/uploads\/2024\/10\/DALL\u00b7E-2024-10-18-15.25.58-An-illustration-of-a-WordPress-testing-process-showing-unit-testing-integration-testing-and-end-to-end-testing.-The-scene-depicts-a-developer-surro-1-12x12.webp 12w, https:\/\/www.openbyt.com\/wp-content\/uploads\/2024\/10\/DALL\u00b7E-2024-10-18-15.25.58-An-illustration-of-a-WordPress-testing-process-showing-unit-testing-integration-testing-and-end-to-end-testing.-The-scene-depicts-a-developer-surro-1-96x96.webp 96w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure><p>Automatisierte Tests sind vorteilhaft, wenn sie in eine Pipeline f\u00fcr kontinuierliche Integration\/kontinuierliche Bereitstellung (CI\/CD) integriert werden. Dienste wie <strong><a href=\"https:\/\/github.com\/features\/actions\" target=\"_blank\" rel=\"noopener\">GitHub-Aktionen<\/a><\/strong> oder<a href=\"https:\/\/docs.gitlab.com\/ee\/ci\/\" data-type=\"link\" data-id=\"https:\/\/docs.gitlab.com\/ee\/ci\/\" target=\"_blank\" rel=\"noreferrer noopener nofollow\"> <strong>GitLab CI<\/strong><\/a> erm\u00f6glichen es Ihnen, Ihre Tests jedes Mal auszuf\u00fchren, wenn Sie Code\u00e4nderungen ver\u00f6ffentlichen. Hier ist ein Beispiel f\u00fcr eine GitHub Actions YAML-Konfiguration f\u00fcr PHPUnit:.<\/p><pre class=\"wp-block-code\"><code># Datei: .github\/workflows\/phpunit.yml\nName: PHPUnit Tests\n\non: [push, pull_request]\n\nJobs:\n  test:\n    l\u00e4uft auf: ubuntu-latest\n\n    Schritte:\n    - name: Checkout code\n      verwendet: actions\/checkout@v2\n\n    - Name: PHP einrichten\n      verwendet: shivammathur\/setup-php@v2\n      mit:\n        php-version: '8.0'\n\n    - name: Abh\u00e4ngigkeiten installieren\n      Ausf\u00fchren: composer install\n\n    - name: PHPUnit ausf\u00fchren\n      Ausf\u00fchren: vendor\/bin\/phpunit<\/code><\/pre><p>Mit dieser Einstellung werden Ihre Unit-Tests jedes Mal ausgef\u00fchrt, wenn neuer Code ver\u00f6ffentlicht oder eine Pull-Anfrage gestellt wird. Durch die Ausf\u00fchrung von Tests in diesen Phasen wird sichergestellt, dass neue \u00c4nderungen keine Regressionen einf\u00fchren oder bestehende Funktionen zerst\u00f6ren, wodurch die Codequalit\u00e4t w\u00e4hrend der gesamten Entwicklung erhalten bleibt. Durch die Einbeziehung von Cypress-Tests in die Pipeline k\u00f6nnen Sie automatisch die Backend-Logik und die Front-End-Interaktionen \u00fcberpr\u00fcfen.<\/p><h3 class=\"wp-block-heading\">Fazit<\/h3><figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"1024\" src=\"https:\/\/www.openbyt.com\/wp-content\/uploads\/2024\/10\/DALL\u00b7E-2024-10-18-15.30.28-An-illustration-showing-a-WordPress-developer-setting-up-automated-testing.-The-developer-is-sitting-at-a-desk-with-multiple-screens-displaying-variou.webp\" alt=\"\" class=\"wp-image-3312\" srcset=\"https:\/\/www.openbyt.com\/wp-content\/uploads\/2024\/10\/DALL\u00b7E-2024-10-18-15.30.28-An-illustration-showing-a-WordPress-developer-setting-up-automated-testing.-The-developer-is-sitting-at-a-desk-with-multiple-screens-displaying-variou.webp 1024w, https:\/\/www.openbyt.com\/wp-content\/uploads\/2024\/10\/DALL\u00b7E-2024-10-18-15.30.28-An-illustration-showing-a-WordPress-developer-setting-up-automated-testing.-The-developer-is-sitting-at-a-desk-with-multiple-screens-displaying-variou-600x600.webp 600w, https:\/\/www.openbyt.com\/wp-content\/uploads\/2024\/10\/DALL\u00b7E-2024-10-18-15.30.28-An-illustration-showing-a-WordPress-developer-setting-up-automated-testing.-The-developer-is-sitting-at-a-desk-with-multiple-screens-displaying-variou-100x100.webp 100w, https:\/\/www.openbyt.com\/wp-content\/uploads\/2024\/10\/DALL\u00b7E-2024-10-18-15.30.28-An-illustration-showing-a-WordPress-developer-setting-up-automated-testing.-The-developer-is-sitting-at-a-desk-with-multiple-screens-displaying-variou-300x300.webp 300w, https:\/\/www.openbyt.com\/wp-content\/uploads\/2024\/10\/DALL\u00b7E-2024-10-18-15.30.28-An-illustration-showing-a-WordPress-developer-setting-up-automated-testing.-The-developer-is-sitting-at-a-desk-with-multiple-screens-displaying-variou-150x150.webp 150w, https:\/\/www.openbyt.com\/wp-content\/uploads\/2024\/10\/DALL\u00b7E-2024-10-18-15.30.28-An-illustration-showing-a-WordPress-developer-setting-up-automated-testing.-The-developer-is-sitting-at-a-desk-with-multiple-screens-displaying-variou-768x768.webp 768w, https:\/\/www.openbyt.com\/wp-content\/uploads\/2024\/10\/DALL\u00b7E-2024-10-18-15.30.28-An-illustration-showing-a-WordPress-developer-setting-up-automated-testing.-The-developer-is-sitting-at-a-desk-with-multiple-screens-displaying-variou-12x12.webp 12w, https:\/\/www.openbyt.com\/wp-content\/uploads\/2024\/10\/DALL\u00b7E-2024-10-18-15.30.28-An-illustration-showing-a-WordPress-developer-setting-up-automated-testing.-The-developer-is-sitting-at-a-desk-with-multiple-screens-displaying-variou-96x96.webp 96w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure><p>Die Implementierung von automatisierten Tests in Ihren WordPress-Workflow ist ein entscheidender Schritt zur Verbesserung der Codequalit\u00e4t und -zuverl\u00e4ssigkeit. Entwickler stehen jedoch oft vor Herausforderungen wie dem Einrichten der Testumgebung, der Verwaltung von Abh\u00e4ngigkeiten und dem Schreiben \u00fcberzeugender Testf\u00e4lle. Die \u00dcberwindung dieser Herausforderungen beinhaltet:<\/p><ul class=\"wp-block-list\"><li>Sorgf\u00e4ltige Planung.<\/li>\n\n<li>Bew\u00e4hrte Verfahren f\u00fcr die Konfiguration der Umgebung verwenden.<\/li>\n\n<li>Nutzen Sie die Ressourcen der Gemeinschaft, um gemeinsame Probleme zu l\u00f6sen.<\/li><\/ul><p>Die ersten Schritte m\u00f6gen zwar wie eine Menge Arbeit erscheinen, aber die langfristigen Vorteile - weniger Fehler, einfachere Wartung und schnellere Bereitstellung - sind es wert. Mit Tools wie PHPUnit und Cypress k\u00f6nnen Sie verschiedene Aspekte des Testens abdecken und eine reibungslose Erfahrung f\u00fcr Entwickler und Benutzer sicherstellen. Auch andere Tools sind eine \u00dcberlegung wert, z.B. Jest f\u00fcr das Testen von JavaScript-Komponenten oder Selenium f\u00fcr umfassendere Browser-Automatisierungstests.<\/p><p>Wenn Sie eine solide Testsuite erstellen und diese in Ihre CI\/CD-Pipeline integrieren, k\u00f6nnen Sie Ihre Funktionen mit der Gewissheit ver\u00f6ffentlichen, dass jeder Code gr\u00fcndlich gepr\u00fcft wurde. Automatisierte Tests sind nicht nur ein schickes Tool, sondern das R\u00fcckgrat eines jeden modernen Entwicklungsworkflows.<\/p><p><\/p>","protected":false},"excerpt":{"rendered":"<p>Automatisierte Tests k\u00f6nnen sich f\u00fcr WordPress-Entwickler entmutigend anf\u00fchlen, vor allem, wenn Sie sich noch nie damit besch\u00e4ftigt haben. Stellen Sie sich vor, Sie h\u00e4tten ein Sicherheitsnetz, w\u00e4hrend Sie...<\/p>","protected":false},"author":31,"featured_media":3318,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[73],"tags":[207,298,206],"class_list":["post-3279","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-automatic-management","tag-automated-testing","tag-ci-cd-integration","tag-wordpress-development",""],"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/www.openbyt.com\/de\/wp-json\/wp\/v2\/posts\/3279","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.openbyt.com\/de\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.openbyt.com\/de\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.openbyt.com\/de\/wp-json\/wp\/v2\/users\/31"}],"replies":[{"embeddable":true,"href":"https:\/\/www.openbyt.com\/de\/wp-json\/wp\/v2\/comments?post=3279"}],"version-history":[{"count":9,"href":"https:\/\/www.openbyt.com\/de\/wp-json\/wp\/v2\/posts\/3279\/revisions"}],"predecessor-version":[{"id":3323,"href":"https:\/\/www.openbyt.com\/de\/wp-json\/wp\/v2\/posts\/3279\/revisions\/3323"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.openbyt.com\/de\/wp-json\/wp\/v2\/media\/3318"}],"wp:attachment":[{"href":"https:\/\/www.openbyt.com\/de\/wp-json\/wp\/v2\/media?parent=3279"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.openbyt.com\/de\/wp-json\/wp\/v2\/categories?post=3279"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.openbyt.com\/de\/wp-json\/wp\/v2\/tags?post=3279"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}