Posts tagged with tdd

Join 9,500+ smart developers

Every month I share what I learn from running Spatie, building Oh Dear, and maintaining 300+ open source packages. Practical takes on Laravel, PHP, and AI that you can actually use.

"Always fresh, useful tips and articles. Carefully selected community content. My favorite newsletter, which I look forward to every time."

Bert De Swaef — Developer at Vulpo & Youtuber at Code with Burt

No spam. Unsubscribe anytime. You can also follow me on X.

Three types of mocks original

by Brent Roose – 3 minute read

Mocking, faking; these might sound like intimidating words if you don't know what they are about, but once you do, you'll be able to improve your testing skills significantly.

Part of "the art of testing" is being able to test code in some level of isolation to make sure a test suite is trustworthy and versatile. These topics are so important that we actually made five or six videos on them in our Testing Laravel course.

In this post, I want to share three ways how you can deal with mocking and faking. Let's dive in!

Read more

Start testing your Laravel applications

jasonmccreary.me

Jason McCreary wrote an epic blogpost on how to get started with tests in a Laravel app. I wish I could have read this when I started out with testing.

This brings me to the next common response, we don’t know where to start testing. This comes in two forms. The first form is quite literally we don’t know which test to write first. The second form is more not knowing how to write the first test. ... Today, I want to focus on getting started with testing your Laravel applications.

Read more [jasonmccreary.me]

Handcrafting mocks original

by Freek Van der Herten – 8 minute read

In an application I was working on I wanted to implement automated tweets. Of course, this logic should also be tested. In this blogpost I'd like to show you how you can easily handcraft your own mocks. Setting things up Let's first take a look at how you can tweet something in PHP. We're going to…

Read more

The Five Types of Test Doubles & How to Create Them in PHPUnit

jmauerhan.wordpress.com

In a new post on her blog Jessica Mauerhan has some good examples on the various types of test doubles.

Did you know that a Mock is only one type of a test double? Most of us use the word “mock” to mean any kind of test double, but there’s actually five different types. It really can help you understand what you’re trying to accomplish with your test if you know a little bit more what you’re doing with your test doubles, so this article will explain the kinds of test doubles, when you use them, how you use them and why.

Read more [jmauerhan.wordpress.com]

The Magic Tricks of Testing

In a mail sent to all subscribers on the testdrivenlaravel.com-mailinglist Adam Wathan mentioned a talk Sandi Metz gave a couple of years ago at Rails Conf. It's a really good talk that explains in a clear way when and what you should test.

Tests are supposed to save us money. How is it, then, that many times they become millstones around our necks, gradually morphing into fragile, breakable things that raise the cost of change? We write too many tests and we test the wrong kinds of things. This talk strips away the veil and offers simple, practical guidelines for choosing what to test and how to test it. Finding the right testing balance isn't magic, it's a magic trick; come and learn the secret of writing stable tests that protect your application at the lowest possible cost.

Read more

A better dd() for your TDD

On the Tighten blog Keith Damiani wrote an article how you can mold the dd helper to your liking.

An important part of every Laravel developer's debugging arsenal is the humble dd() helper function—"dump and die"—to output the contents of a variable and terminate execution of your code. In the browser, dd() results in a structured, easy-to-read tree, complete with little arrow buttons that can be clicked to expand or hide children of nested structures. In the terminal, however, it's a different story. ... Fortunately, it's simple to build your very own customized version of dd() to help tame your unwieldly terminal output.

https://blog.tighten.co/a-better-dd-for-your-tdd

Read more

Test Driven API Development using Laravel, Dingo and JWT with Documentation

In a new tutorial posted at dotdev.co Diaa Fares shows a good way to develop API's using Laravel. Along the way he touches on the Dingo packages, JSON Web tokens and documentation generation.

Let’s look at everything we will cover: Landmark 1: Prepare our TDD environment and creating our first test. Landmark 2: Installing and configuring Dingo API package. Landmark 3: What are Transformers, why the need for them and how to use thephpleague/fractal as our transformation layer. Landmark 4: Introduction about JWT and how to use tymondesigns/jwt-auth for our token based authentication. Landmark 5: How to use laravel-apidoc-generator to generate nice documentation for our API. So, pack your bags and let’s dive into our journey!

https://dotdev.co/test-driven-api-development-using-laravel-dingo-and-jwt-with-documentation-ae4014260148#.iynir3ftm

Read more

Type Wars

The venerable Uncle Bob makes the case for dynamic typing and TDD. Be sure to read the entire article to get a quick history lesson in computer languages.

The pendulum is quickly swinging towards dynamic typing. Programmers are leaving the statically typed languages like C++, Java, and C# in favor of the dynamically typed languages like Ruby and Python. And yet, the new languages that are appearing, languages like go and swift appear to be reasserting static typing? So is the stage for the next battle being set?

How will this all end?

My own prediction is that TDD is the deciding factor. You don't need static type checking if you have 100% unit test coverage. And, as we have repeatedly seen, unit test coverage close to 100% can, and is, being achieved. What's more, the benefits of that achievement are enormous.

http://blog.cleancoder.com/uncle-bob/2016/05/01/TypeWars.html

Read more

Approaches to Testing: A Survey

The last few months have been my first opportunity to do automated testing at my full-time job. As I’ve been trying to get the hang of it, my biggest question has been how many of each type to test to write: how many unit, integration, and acceptance tests. Turns out Folks Got Opinions™ on this! As I researched, I found at least four different approaches to testing, and they each provide different answers to a number of questions I had.
http://codingitwrong.com/2016/02/08/approaches-to-testing-a-survey.html

Read more