Articles tagged 'testing'
-
Page Objects: Where do you put your assertions?
April 12, 2016
I started writing about Page Objects earlier this month, and as soon as you start talking about Page Objects, you need to have an opinion about where to put your assertions. Do you ask the page if it is in the state it expects to be or do you ask the page for values and assert that they are what you expect them to be in the test?
If you look at FluentLenium and Simplelenium on GitHub, you’ll notice that their corresponding
README
s describe the usage of the Page Object pattern. Now, if you take a closer look, you’ll also notice that they have an opinion: they’ve included the assertions in the definition of such Page Objects.Now, my first experience with Page Objects was actually under these conditions. The Page Objects were the main driver…
-
Specifying failure message for RSpec expectations
April 12, 2016
When writing the Unit Testing ActiveRecord eager-loading blog post a couple months ago, I noticed that the test failures I was getting while writing were not very helpful. Initially, I had an assertion that looked like this:
expect(restaurant.association(:reviews)).to be_loaded
Since I was writing the test before the implementation — *cough* TDD isn’t dead *cough* — I got the expected failure when running it. However, the failure message was not that friendly after all:
$ rspec spec/controllers/restaurant_controller_spec.rb Failures: 1) RestaurantsController#index eager loads Failure/Error: expect(restaurant.association(:reviews)).to be_loaded expected `#<ActiveRecord::Associations::HasManyAssociation (...) >.loaded?` to return…
-
Using Page Objects in your Acceptance Tests
April 10, 2016
If you’ve written acceptance tests for web applications in the past (also called feature tests), you might be familiar with tools like Capybara, Simplelenium and FluentLenium. These are great abstractions over the browser (thanks, Selenium!) that provide very nice APIs for testing web applications.
If you’ve done this for a while, you might also have heard of Page Objects. The idea behind them is that your tests should be about the behavior of your application and not about the underlying HTML, since the HTML is an implementation detail and probably not the interesting part of your tests.
Our base acceptance test
Let’s assume that we are working on an application where you can browse and review restaurants and we have an acceptance test…
-
Unit Testing ActiveRecord eager-loading
January 27, 2016
If you’ve worked with relational databases and any ORMs like Java’s Hibernate, .NET’s NHibernate or Rails’
ActiveRecord
in the past, you might be familiar with SELECT N+1 issues. It is a common performance problem in database-dependent applications and, because of this, these ORMs provide a built-in solution to this problem.In
ActiveRecord
,includes
,preload
andeager_load
come to the rescue. Therefore, it is not unusual to find these keywords scattered in different places where your application accesses the database. Hopefully this isn’t a lot of places though - you are using Query Objects, right?An example application
Let’s imagine for a second that we have an application where you can browse restaurants, which in turn have many reviews…
-
Unit testing the jQuery Rambling Slider - Part 2 - The DOM, jQuery and node.js
November 9, 2011
This post was originally published in the Rambling Labs Blog on November 9, 2011.
In order to continue to add tests to the jQuery Rambling Slider, I needed to test something against the DOM. Problem is, you don’t count with the DOM when you’re running the Jasmine tests from console. So what should I do?
As expected, I found that there is a DOM emulator in node.js :D. Also, to test using jQuery I needed to download the corresponding node package. So I didn’t waste any time and went ahead to install them:
npm install -g jsdom npm install -g jquery
So now, I can write something like this in my
src/jquery.plugins.coffee
:(($) -> $.fn.reverse = [].reverse )(jQuery)
And test it on my
spec/jquery.plugins.spec.coffee
with something like this… -
Unit testing the jQuery Rambling Slider - CoffeeScript, Jasmine and node.js
November 9, 2011
This post was originally published in the Rambling Labs Blog on November 9, 2011.
As you may know, I have been working lately on the jQuery Rambling Slider. One of my personal milestones with this project is to write as many unit tests as possible, so I began my research.
Honestly, I didn’t know where to begin. I remember to have read once on twitter that someone was writing their tests with Jasmine and CoffeeScript, so that could be a good starting point (and it sounds really fun too!). I have worked with Jasmine before and it sure was a great experience. It’s yet another productivity tool made by the great Pivotal Labs guys.
After googling for a while, I stumbled into a post from someone that was writing tests in Jasmine and node.js