jacopo beschi: yet another web guy

Testing Archive

Testing for custom Rails validators with Rspec and metaprogramming

Created at: Apr/25/2015 jacopo beschi

Hello guys, some days ago I've made a custom validator for Rails and I wanted to test that it was used correctly in my model (which uses ActiveModel::Model). As a brief preface you have to know that to test for the common Rails validators you can use the shoulda matchers library.

Read on

Test double php introduction

Created at: Nov/20/2014 jacopo beschi

When you start unit testing your code you don't want to test a full behavior of your code but just a little part in isolation to the rest. In order do do that you need to isolate your class from the other context, test doubles are tools (aka patterns) that allow you to do that. There are five common test double:

  1. Dummy
  2. Stub
Read on

Laravel Testing Redirect::back()

Created at: Oct/22/2014 jacopo beschi

Hello guys, sometimes in your functional test you need to test a redirect, this is pretty easy to test except for the Laravel Redirect::back() method. I've found out that this is hard to test and the only solution to solve the problem is to fake a HTTP_REFERRER value.

Read on

Testing in Laravel framework: step2 TDD calculator

Created at: Aug/21/2014 jacopo beschi

Hello again, in the previous article i've explained how to run your first test. Now we go a little more in detail and we tackle a real example.What we are going to do is write the calculator in TDD (test first). We incrementally build the calculator step after step. The step will be the following:

  1. Create a simple String calculator with a method int Add(string numbers)
  2. The method can take 0, 1 or 2 numbers, and will return their sum (for an empty string it will return 0) for example “” or “1” or “1,2”
  3. Allow the Add method to handle an unknown amount of numbers
Read on

Introduction to Unit testing with Laravel framework: step1

Created at: Jul/31/2014 jacopo beschi

When i first came into programming i didn't even know what self tested code was and how much it's important for a developer. This article is for developers that want to start unit testing with laravel framework or php in general. Before going into details i'd like to explain you briefly what is unit testing and automated code tests. Automated code tests are programs that verify automatically that your application works as expected. Why self tested code is important? For multiple reasons, the most important is that removes the "fear of change" and for this reason help you refactoring your code and improving it.

Read on