Last Updated on April 3, 2025 by Mike Kipruto
As a developer, upskilling is essential for growth. Wanting to deepen my understanding of automated testing, I enrolled in a Codeception course on Udemy. Since then, I’ve been applying it to my website, mike.co.ke. If you’re exploring testing for your projects, my journey might offer some useful insights!
Setting Up My Testing Environment
The first step was to set up Codeception on my development machine. Here’s what I did:
- Installed Composer: This is PHP’s package manager, which is essential for managing dependencies.
- Executed Commands in My Website’s Directory:
composer require codeception/codeception --dev vendor/bin/codecept bootstrap
My First Test: Homepage Check
To get started, I wrote a simple test to verify if my homepage was loading correctly. Below is the basic test I created:
<?php
$i = new AcceptanceTester($scenario);
$i->amOnPage('/');
$i->see('Welcome to Mike\'s website');
$i->seeElement('.main-navigation');
$i->seeElement('.footer');
This test essentially:
- Navigates to my homepage.
- Checks for the welcome message.
- Verifies the existence of the navigation menu.
- Ensures that the footer is present.
Testing My Contact Form
The contact form on my site had always shown some quirks, so I decided to write a test for it as well:
<?php
$i = new AcceptanceTester($scenario);
$i->amOnPage('/contact');
$i->fillField('name', 'test user');
$i->fillField('email', 'test@example.com');
$i->fillField('message', 'This is a test message');
$i->click('submit');
$i->see('Thank you for your message');
What I Learned
Writing these tests provided me with several insights:
- Start Small: It’s crucial to begin with small cases and gradually build complexity.
- Prioritize Important Features: Focus on testing the core functionalities first.
- Keep It Simple: Ensure tests are straightforward and target specific outcomes.
- Run Tests Pre-Update: Always execute tests before deploying changes to the live environment.
A Few Challenges I Faced
- Setting Up the Test Database: This was initially tricky, but I learned to handle it.
- Structuring Test Files: Understanding the correct structure took some time.
- Finding the Right Selectors: Locating suitable selectors for elements wasn’t always easy.
How I Run My Tests
I created a simple Bash script to automate running my tests:
#!/bin/bash
vendor/bin/codecept run acceptance
Now, I execute this script before pushing any updates to my live site.
Next Steps
Moving forward, I plan to:
- Expand tests for my blog section.
- Set up automated testing using GitHub Actions.
- Evaluate my site’s responsiveness.
- Write tests specifically for admin functions.
Tips for Beginners
If you’re diving into testing like I did, here are some tips:
- Take it one step at a time.
- Start with simple tests.
- Don’t strive for perfection right away.
- Organize your test code from the beginning.
Embracing testing might feel like extra work initially, but it has saved me from deploying broken code to my live site multiple times. It’s worth every minute spent learning!