Josheli
  • Home
  • Blog
    • Knob
    • Running
    • Soccer
    • Technology
  • About
Knob , Technology

Automated Testing with Codeception

by dv February 12, 2016 No Comments

I gave a little presentation at work the other day on using automated testing in my Laravel project using Codeception. Here’s a screencast. The audio is a little low, so there’s a basic transcript below the video. Enjoy.

==========================================
Transcript…
==========================================

[chrome: show feature request in jira]
so here’s a little example of writing an automated test to confirm a new feature.

[switch to jira]
there’s a request in my issue tracker to sort any “Other” option in dropdowns to
the bottom of the dropdown list.

[chrome: show “before” example in metrics]
see here how “other” gets lost in the list. we want it at the bottom. so let’s switch over to do that.

[phpstorm: implement feature]
ok, i can add the feature with a few lines of code. since this is a demo i already have the solution
i can just copy/paste in… save it. now back over to chrome

[chrome: show “after” example]
…and in the form and there’s “other” listed at the bottom. that’s great, perfect.

but we don’t want to have to manually test that this feature works every time i make
any new change to the code. i’d probably forget to test this little bit of
functionality if i had to do it manually. so it would be great if i could just push a button
and run automatic tests whenever i change any code in the application. that way we can make
sure we don’t break existing features like this nifty one we just implemented.

[phpstorm: add empty test and run showing failure]
so let’s do that. let’s create a test for this feature.

[type …]
and let’s fail the test for now, to
remind us that we need to implement it. as a quick aside, i’m using a package called “codeception”
for my test suite.

[switch to codeception website]
codeception is an automated test framework written in PHP. it has different modules for various things like database testing, rest api testing, testing frameworks like laravel or symfony, and other stuff.
of course there’s plenty of other test frameworks you could use, like PHPUnit, Selenium,
Drupal’s built-in SimpleTest … but i like codeception for what i’m doing.

[phpstorm: run test]
anyway, let’s run our failing test … and of course it fails. so we need to make it not fail.

[phpstorm: test code]
luckily, i already have some test code here i’ll just paste in. this is pretty self-explanatory i think.
we tell it to log in, go to the particular page with the form on it, grab the dropdown options, and
assert that “other” is at the bottom.

[phpstorm: run test ]
so now let’s run the test … and hey success! the test passes. now anytime in the future
whenever i change code, i can run this automated test and get immediate assurance that i didn’t
break anything, at least not this feature.

for metrics, the api and supporting code, i’ve written almost 50 tests with 500 assertions. that’s
basically 500 manual tests i don’t have to run each time.
and so when i work on the code, i can press a button and run these suite of tests, and feel much
more confident that i haven’t broken anything.

so that’s a little intro to automated testing. hope it’s helpful. thanks.

Related Content:

  • Project JoRViP: Josheli Running Video Producer by Dv February 2, 2022 I produce videos for the Josheli Running YouTube channel. Producing videos is tedious and time-consuming. It'd be great if I…
  • Continuous Deployment: Drupal 8, Composer, Github,… by Dv April 17, 2018 UPDATE: Watch a tech talk I recently gave at work about this process. I've been doing some pretty cool work…
  • Migrating a Laravel application to Symfony by Dv April 15, 2019 When I started at the day job about 6.5 years ago, I inherited a jumble of custom PHP/MySql web applications.…
  • Aptana Studio 3 Sync with Mapped Drives by Dv December 2, 2011 Soldiering on with Aptana, fighting as I go, here's how I was able to set up automatic synchronization between my…
  • Laravel, Composer and Optimize by Dv February 18, 2016 So I write these little tech snippets mostly as a personal journal for my future self. Anyway, got caught again…
It's only fair to share...Share on facebook
Facebook
Share on twitter
Twitter
Share on email
Email
  • Previous PHP, JSON, Strings, Integers, Mysqlnd and Matching Environments9 years ago
  • Next More Janky Snowboarding Video9 years ago

Leave a Reply

Your email address will not be published. Required fields are marked *

Popular Posts

  • Josheli, What Happened? (55,148)
  • Stupidly Simple, Static, Startpage for Self-hosted Services (30,211)
  • Running a Plex Media Server on an Old Laptop (26,081)
  • Simple Google Photos: A WordPress Plugin (22,979)
  • Three Saturdays (22,534)

Random Read

On motivation
I was talking yesterday with a friend of mine who owns a fairly large company…

Read More

Google Photo
Google Photo
Google Photo
Google Photo

Social Things

  • Family Vance
  • Texas Longhorns News

RSS From Familyvance

2025 Josheli. Donna Theme powered by WordPress