SlideShare a Scribd company logo
1 of 58
Download to read offline
Testing Ember Apps
                                          Jo Liss

                         https://twitter.com/jo_liss
Hi, Iā€™m Jo, Iā€™m on the
                           http://solitr.com/blog
Capybara and Konacha
core teams, and Iā€™m an
Ember contributor.
                                                                   This talk will be more an
                                                                   architectural over view
                                                                   than a tutorial. Iā€™ll
                                                                   assume Rails in some
                                                                   places, but the concepts
                                                                   apply to other backends
                                                                   as well.



                                Slides licensed under CC BY 3.0.
This presentation has 2 parts:




Part 1: Full-Stack Integration Tests
                                  Capybara   similar: PhantomJS
Part 1: Full-Stack Integration Tests
              Capybara

Part 2: Client-Side Integration Tests
               Konacha   similar: QUnit, Mocha, Jasmine




                                I like to test apps with a
                                combination of Capybara
                                and Konacha tests.

                                I noticed that having a
                                good test suite makes me
                                *much* more productive.
Part 1: Full-Stack Integration Tests
              Capybara

                            Itā€™s not very hard to get
                            Capybara working right.
                            So I want to focus on
                            high-level architecture
                            instead. I think thatā€™s
                            sometimes under-
                            appreciated.
Capybara
Quick refresher:




                            ā€œSelenium for Railsā€


                   You can plug in different   Q: Who has used Capybara to
                   drivers, like WebKit. All   test a JavaScript app?
                   of the following applies                                      ------->
                   to any driver.              Q: Who ran into problems with
                                               either performance, or
                                               flickering tests (brittleness)?
Capybara
These pains are architectural.


                  These pains are because of the
                  architecture.
Capybara
These pains are architectural.

       Performance :-(
        Brittleness :-(

         There are probably limits      So letā€™s talk about why
         to how fast you can            this happens.
         make Capybara tests.

         And you can hunt down
         flickering tests (and you
         should), but they will still
         pop up occasionally.
So you have a test suite
written in Ruby, and it
talks to a DB backend.




                                Test suite



                           DB
Firefox +           So when you have a
                    Capybara test, Capybara
                    will automatically spin up a
Selenium            Firefox for you, and your
                    test suite will send requests
                    to that Firefox.




            Test suite

               But Selenium commands are mostly
               non-blocking, i.e. they return before
               they finish. So when you have a

  DB           sequence of commands, even with
               Ajax, Capybara does some intelligent
               polling to make them appear
               synchronous.

               This works transparent 99% of the
               time, and it makes for very readable
               test code, but very occasionally, youā€™ll
               end up with a race condition, and then
               you have to understand whatā€™s going
               on underneath.

               So let me double that line to indicate
               that itā€™s async.
So who does the Firefox make
Firefox +   HTTP requests to? Clearly, Ruby is
            busy with the test suite.

Selenium    Capybara actually spins up
            another ser ver thread.




            Test suite



  DB
Firefox +
                            Selenium



     Server                             Test suite


So now Firefox has a
server to load the pages      DB
from.

If thereā€™s Ajax requests,
this whole thing becomes
asynchronous. So thatā€™s
another source of race
conditions. Let me double
that line...
Firefox +
                           Selenium



               Server                  Test suite


And of course the server
talks to the database --     DB
another line...
Firefox +
                            Selenium



            Server                          Test suite


Which means you also                    This is clearly fundamentally quite complex
have to be careful not to
have the t wo Ruby            DB        and error-prone.

threads interfere with                  Iā€™m not trying to convince you that Capybara
each other while they                   is a bad tool. But I think itā€™s actually useful to
access the database.                    understand this architecture.

                                        By the way, just to be clear, thatā€™s not
                                        Seleniumā€™s fault. If you drop in WebKit or
                                        PhantomJS into Capybara, it suffers from the
                                        same issues.
Firefox +
                  Selenium


         At the moment, this kind of architecture is
         the only solution to give us a full-stack
         integration test, database to DOM. So itā€™s
         actually very useful.
Server   If you donā€™t use Rails, Iā€™d definitely        Test suite
         recommend finding a comparable solution,
         or hand-rolling one.




                         DB
Capybara
Powerful but clunky
                      So one solid strategy ...
... is limiting yourself to
                           exercising one happy path for



         Capybara
                           each model, to make sure that
                           stuff in the DB ends up in the
                           DOM, and vice versa.




Powerful but clunky
Strategy: Only test every model once
   DB-to-DOM, read and write
And then we can use pure client-
                             side integration testing to get



          Capybara
                             more fine-grained testing.




Powerful but clunky
Strategy: Only test every model once
   DB-to-DOM, read and write
Move ļ¬ner-grained tests to client side
Part 2: Client-Side Integration Tests
                             with Konacha
       The idea is to limit the
       architectural complexity.
       No backend server, no DB,
       test runs directly in the
       browser, not in a separate
       process.

       This makes it faster, and
       extremely reliable.
Konacha
Rails gem packaging
                                               Konacha is pretty

Mocha.js testing framework +                   simple, so if youā€™re not on
                                               Rails, you can easily
                                               hand-roll an equivalent
                                               test setup.

Chai.js assertion lib
                        Let me show you what
                        Mocha and Chai do...
Mocha + Chai
describe 'todo list', ->
  it 'can add items', ->

             Mocha is a testing
             framework, like QUnit or
             Jasmine, or RSpec on
             Ruby.

             But Mocha doesnā€™t do
             assertions, so you
             typically combine it with
             the Chai assertion
              library.
Mocha + Chai
describe 'todo list' ->
  it 'can add items', ->
    ...
    $('.todo').should
      .contain 'Buy milk'
Interlude: Konacha Video
 Before I go on, let me show you
 what weā€™re trying to achieve.




http://www.youtube.com/watch?v=heK78M6Ql9Q
                                   So we basically just hit Cmd+R on
                                   Konachaā€™s development ser ver.

                                   Konacha automatically runs your tests in
                                   an iframe, and loads your application.css.
                                   Thatā€™s also really easy to do yourself if
                                   you donā€™t use Rails with Konacha.

                                   This is also really useful to ramp up people
                                   to Ember, because you can visually see
                                   what your test does. And if a test fails,
                                   you can just click into the iframe and
                                   interact with the application.
Konacha
In the browser (Cmd+R) for dev
rake task for CI   CI task through Capybara
Why is Konacha fast?
No page loads   You donā€™t have to serve and parse the entire
                stack of assets for every test case.
Why is Konacha fast?
No page loads
100% synchronous   No polling, no waiting.
Why is Konacha fast?
No page loads
100% synchronous
No stack   Most expensive thing is the DOM.
Unit vs. Integration
What you just saw I call ā€œclient-side
integration testsā€. They donā€™t involve the
backend, but on the frontend, they exercise
the entire Ember app.
Unit vs. Integration
Lots of simple layers ==> integration
tests win.
 On Ember, I avoid unit tests. The reason is, the
 individual layers of an Ember app are very
 simple. What I care about is whether they play
 together. Unit tests tend to be very ā€œweakā€, i.e.
 theyā€™ll just keep passing even when your app
                                                     Okay, breadā€™nā€™butter
 breaks.
                                                     time.
 As a rule of thumb, I tend to do zero unit
 testing for Ember apps.
Ember setup
No ā€œofļ¬cialā€ support for testing.
So we wing it.                A bunch of pieces are
                              missing to make this
                              easy like with Rails.

                              (Notably, good fixture
                              handling, package
                              manager, ...)

                              Hereā€™s some practical
                              tips:
Thereā€™s no repeated app
instantiation yet, so I
like to start up the



                          Starting the app
application at the
beginning of the entire
test suite.
Starting the app
# Parse time:              We call
                           App.deferReadiness, and
                           advance readiness it

App.deferReadiness()       once you want the app to
                           run.



# Global before all:
before ->                   UPDATE Feb 26 2013:

  App.advanceReadiness()    Instead you can now Enable
                            Ember.testing *before*
                            parsing your app code, and
                            kick it off with ā€œbefore ->
                            App.initialize()ā€; no more
                            advanceReadiness.
Router
                     We tell the router not to
                     mess with the URL.


App.Router.reopen
  location: 'none'
Router
App.Router.reopen
  location: 'none'
beforeEach: ->
 App.router.transitionTo('...')
       Before each test,          UPDATE Feb 26 2013:
       transition back to the
       root state.                You can now use
                                  ā€œbeforeEach ->
       This is a pretty hackish   App.reset()ā€.
       way to reset app state,
       but for now itā€™s
       surprisingly reliable.
Reset store
beforeEach ->

  App.store.destroy() if App.store

  App.store = DS.Store.create()
Konacha: Keep body
Konacha.reset = function() { }

                 Konacha by default
                 cleans the <body>
                 element before each test.
                 But our app keeps
                 running bet ween tests,
                 so we disable this by
                 nuking Konacha.reset.
Runloop & setTimeout
                       Ember automatically
                       schedules runloops with
                       setTimeout. But setTimeout is

Ember.testing = true
                       the enemy of deterministic
                       tests. So we disable
                       automatic runloop creation
                       by enabling the Ember.testing
                       flag.

                       You want to put this before
                       loading (parsing) your app
                       modules.
Runloop & setTimeout
Ember.testing = true

Itā€™s OK to have Em.run everywhere:
Em.run => foo.set ...
Em.run => $(...).click()       Most actions have their
                               effects deferred to the
                               end of the runloop. In test
                               code you need the effects
                               immediately, so you wrap
                               things in Ember.run.
                               Looks funny, but itā€™s
                               nothing to worry
                               about. :-)
Animations
jQuery.fx.off = true
Nothing like this for D3. :-(              This is not Ember-related,
                                           but you donā€™t want
                                           animations, because they
                                           are asynchronous. For
                                           D3,, this may require
                                           support in your
                                           production code. :-(




                 Probably the trickiest
                 thing is data fixtures:
Model Fixtures
1. Client-side ļ¬xtures.   You have a choice
                          whether you write them
                          in JavaScript or

2. Server-side ļ¬xtures.   generate them from the
                          server side, and itā€™s kind
                          of a trade off.
(1) Client-Side Fixtures
FixtureAdapter (immature)
App.TodoList.FIXTURES = [
    { ... }, { ... }
                     For client-side fixtures,

]                    there is a FixtureAdapter
                     in Ember. It still needs
                     some love, but we can
                     probably get it there
                     pretty soon.

                     And basically you just
                     define an array of
                     fixtures for every model.
(1) Client-Side Fixtures
:-) Easy   to set up
(1) Client-Side Fixtures
:-) Easy
:-( Goes out of sync with backend
       But you donā€™t know if
       your fixtures actually
       represent the reality of
       your backend.
(1) Client-Side Fixtures
:-) Easy
:-( Goes out of sync with backend
:-( Fragile   You can even have bugs
              in your fixtures, where
              you donā€™t set up
              bidirectional belongsTo
              and hasMany
              relationships properly.
(1) Client-Side Fixtures
:-) Easy
:-( Goes out of sync with backend
:-( Fragile
:-( Server-side computed attributes
 JavaScript is still not very powerful. Oftentimes itā€™s       So the alternative to all
 easier in practice to implement computed properties on the   this is...
 backend side and ser ve them out as read-only attributes.

 In one backend I worked on, half of the properties were DB
 columns, and half were just methods on the Rails models.

 Trying to keep these properties manually updated in your
 fixture data is obviously painful.
(2) Server-Side Fixtures
  rake test:fixtures
1. Write ļ¬xtures to DB
2. Generate JSON to ļ¬xtures.js
(2) Server-Side Fixtures
     rake test:fixtures
1. Write ļ¬xtures to DB
2. Generate JSON to ļ¬xtures.js
     Load through RESTAdapter
Load that data in fixtures.js before every test
case, perhaps using your RESTAdapter so you
translate the JSON correctly.
(2) Server-Side Fixtures
 :-) Covers models, serializers, adapter
               with no speed penalty
(2) Server-Side Fixtures
 :-) Covers models, serializers, adapter
 :-) Easy to maintain   Compact definitions, esp. w/ FactoryGirl; stuff doesnā€™t
                        go out of sync.
(2) Server-Side Fixtures
 :-) Covers models, serializers, adapter
 :-) Easy to maintain
 :-( Usability   Generated fixtures file can go stale and you have to regenerate. Itā€™s not bad,
                 just bothersome.
(2) Server-Side Fixtures
 :-) Covers models, serializers, adapter
 :-) Easy to maintain
 :-( Usability
 :-( Complex to set up       Work to set up. You end up with some
                             custom code, and it ties tightly into
                             backend.

                             I personally think itā€™s generally worth it,
                             but it also depends on your specific app.
Fixture Woes
Global ļ¬xtures :-(   Both of these techniques
                     mean that you have the same
                     fixture set for the entire test
                     suite.

  want FactoryGirl   Ideally weā€™d build something
                     like FactoryGirl, but I donā€™t
                     think weā€™re quite there yet.
Bonus: JS-driven?
Capybara but in JavaScript?
                      One thing that
                      sometimes comes up is,
                      can we have a full-stack
                      integration test written
                      in JavaScript?
Firefox +
                       So instead of having the
         Selenium      Test suite written in
                       Ruby...




Server               Test suite



           DB
Firefox w/
           JS tests
                      ... we push them into the
                      browser, and so we avoid
                      the t wo-threaded problem.




Server
                          I think that would be
                          really awesome -- and the
                          truth is, we just donā€™t have
                          the tooling yet to make
                          that work easily.

                          Perhaps the biggest hurdle

           DB             is that we donā€™t have a way
                          to reset the database, add
                          fixtures, and perhaps
                          query database records
                          from JavaScript.

                          But it is probably a good
                          direction to move towards
Q &A
Notes from the talk, thanks to @cgcardona:
Q: With Konacha do you see opportunity for TTD?
A: Not quite TDD (hard with visual stuff), but continuous.
When working with Konacha I wrote tests as I went.
Q: Can you test views in isolation?
A: Itā€™s really tricky to instantiate a view in isolation, Ember
wants a whole appā€¦ Itā€™s too ā€˜unit testyā€™. It might be
possible.
Q &A
Comment: We use ā€˜Rosieā€™ (https://github.com/bkeepers/
rosie) for Javascript factories.
Comment: Have you tried VCR for server side things? Itā€™s a
Ruby library that will record request responses so you can
play them back later. We run VCR against a live production
server and generate response data that the tests use.
Q &A
Q: A lot of bugs come from asynchronicity. Have you tried
to test that speciļ¬cally?
A: No I havenā€™t. My hope is that a lot of these bugs
disappear with ember-data. Mocha allows for asynchronous
tests where you set a callback for when your test is
complete.
Thanks for listening!


Jo
https://twitter.com/jo_liss
http://solitr.com/blog

More Related Content

What's hot

Using Java from Ruby with JRuby IRB
Using Java from Ruby with JRuby IRBUsing Java from Ruby with JRuby IRB
Using Java from Ruby with JRuby IRBHiro Asari
Ā 
Torquebox OSCON Java 2011
Torquebox OSCON Java 2011Torquebox OSCON Java 2011
Torquebox OSCON Java 2011tobiascrawley
Ā 
JRuby in Java Projects
JRuby in Java ProjectsJRuby in Java Projects
JRuby in Java Projectsjazzman1980
Ā 
Torquebox @ Raleigh.rb - April 2011
Torquebox @ Raleigh.rb - April 2011Torquebox @ Raleigh.rb - April 2011
Torquebox @ Raleigh.rb - April 2011tobiascrawley
Ā 
Ruby Plugins for Jenkins
Ruby Plugins for JenkinsRuby Plugins for Jenkins
Ruby Plugins for Jenkinscowboyd
Ā 
Sparklife - Life In The Trenches With Spark
Sparklife - Life In The Trenches With SparkSparklife - Life In The Trenches With Spark
Sparklife - Life In The Trenches With SparkIan Pointer
Ā 
Why JRuby?
Why JRuby?Why JRuby?
Why JRuby?Fiona Tay
Ā 
RubyConf 2009
RubyConf 2009RubyConf 2009
RubyConf 2009John Woodell
Ā 
Ruby on Rails survival guide of an aged Java developer
Ruby on Rails survival guide of an aged Java developerRuby on Rails survival guide of an aged Java developer
Ruby on Rails survival guide of an aged Java developergicappa
Ā 
3978 Why is Java so different... A Session for Cobol/PLI/Assembler Developers
3978   Why is Java so different... A Session for Cobol/PLI/Assembler Developers3978   Why is Java so different... A Session for Cobol/PLI/Assembler Developers
3978 Why is Java so different... A Session for Cobol/PLI/Assembler Developersnick_garrod
Ā 
Charla ruby nscodermad
Charla ruby nscodermadCharla ruby nscodermad
Charla ruby nscodermadnscoder_mad
Ā 
Your Goat Antifragiled My Snowflake!: Demystifying DevOps Jargon - ChefConf 2015
Your Goat Antifragiled My Snowflake!: Demystifying DevOps Jargon - ChefConf 2015Your Goat Antifragiled My Snowflake!: Demystifying DevOps Jargon - ChefConf 2015
Your Goat Antifragiled My Snowflake!: Demystifying DevOps Jargon - ChefConf 2015Chef
Ā 
Reactor grails realtime web devoxx 2013
Reactor grails realtime web   devoxx 2013Reactor grails realtime web   devoxx 2013
Reactor grails realtime web devoxx 2013StƩphane Maldini
Ā 
Open Source Compiler Construction for the JVM
Open Source Compiler Construction for the JVMOpen Source Compiler Construction for the JVM
Open Source Compiler Construction for the JVMTom Lee
Ā 
Java 7 Whats New(), Whats Next() from Oredev
Java 7 Whats New(), Whats Next() from OredevJava 7 Whats New(), Whats Next() from Oredev
Java 7 Whats New(), Whats Next() from OredevMattias Karlsson
Ā 
Connecting the Worlds of Java and Ruby with JRuby
Connecting the Worlds of Java and Ruby with JRubyConnecting the Worlds of Java and Ruby with JRuby
Connecting the Worlds of Java and Ruby with JRubyNick Sieger
Ā 
Java, Ruby & Rails
Java, Ruby & RailsJava, Ruby & Rails
Java, Ruby & RailsPeter Lind
Ā 
JRuby and You
JRuby and YouJRuby and You
JRuby and YouHiro Asari
Ā 
Unit Testing in AngularJS - CC FE & UX
Unit Testing in AngularJS -  CC FE & UXUnit Testing in AngularJS -  CC FE & UX
Unit Testing in AngularJS - CC FE & UXJWORKS powered by Ordina
Ā 

What's hot (19)

Using Java from Ruby with JRuby IRB
Using Java from Ruby with JRuby IRBUsing Java from Ruby with JRuby IRB
Using Java from Ruby with JRuby IRB
Ā 
Torquebox OSCON Java 2011
Torquebox OSCON Java 2011Torquebox OSCON Java 2011
Torquebox OSCON Java 2011
Ā 
JRuby in Java Projects
JRuby in Java ProjectsJRuby in Java Projects
JRuby in Java Projects
Ā 
Torquebox @ Raleigh.rb - April 2011
Torquebox @ Raleigh.rb - April 2011Torquebox @ Raleigh.rb - April 2011
Torquebox @ Raleigh.rb - April 2011
Ā 
Ruby Plugins for Jenkins
Ruby Plugins for JenkinsRuby Plugins for Jenkins
Ruby Plugins for Jenkins
Ā 
Sparklife - Life In The Trenches With Spark
Sparklife - Life In The Trenches With SparkSparklife - Life In The Trenches With Spark
Sparklife - Life In The Trenches With Spark
Ā 
Why JRuby?
Why JRuby?Why JRuby?
Why JRuby?
Ā 
RubyConf 2009
RubyConf 2009RubyConf 2009
RubyConf 2009
Ā 
Ruby on Rails survival guide of an aged Java developer
Ruby on Rails survival guide of an aged Java developerRuby on Rails survival guide of an aged Java developer
Ruby on Rails survival guide of an aged Java developer
Ā 
3978 Why is Java so different... A Session for Cobol/PLI/Assembler Developers
3978   Why is Java so different... A Session for Cobol/PLI/Assembler Developers3978   Why is Java so different... A Session for Cobol/PLI/Assembler Developers
3978 Why is Java so different... A Session for Cobol/PLI/Assembler Developers
Ā 
Charla ruby nscodermad
Charla ruby nscodermadCharla ruby nscodermad
Charla ruby nscodermad
Ā 
Your Goat Antifragiled My Snowflake!: Demystifying DevOps Jargon - ChefConf 2015
Your Goat Antifragiled My Snowflake!: Demystifying DevOps Jargon - ChefConf 2015Your Goat Antifragiled My Snowflake!: Demystifying DevOps Jargon - ChefConf 2015
Your Goat Antifragiled My Snowflake!: Demystifying DevOps Jargon - ChefConf 2015
Ā 
Reactor grails realtime web devoxx 2013
Reactor grails realtime web   devoxx 2013Reactor grails realtime web   devoxx 2013
Reactor grails realtime web devoxx 2013
Ā 
Open Source Compiler Construction for the JVM
Open Source Compiler Construction for the JVMOpen Source Compiler Construction for the JVM
Open Source Compiler Construction for the JVM
Ā 
Java 7 Whats New(), Whats Next() from Oredev
Java 7 Whats New(), Whats Next() from OredevJava 7 Whats New(), Whats Next() from Oredev
Java 7 Whats New(), Whats Next() from Oredev
Ā 
Connecting the Worlds of Java and Ruby with JRuby
Connecting the Worlds of Java and Ruby with JRubyConnecting the Worlds of Java and Ruby with JRuby
Connecting the Worlds of Java and Ruby with JRuby
Ā 
Java, Ruby & Rails
Java, Ruby & RailsJava, Ruby & Rails
Java, Ruby & Rails
Ā 
JRuby and You
JRuby and YouJRuby and You
JRuby and You
Ā 
Unit Testing in AngularJS - CC FE & UX
Unit Testing in AngularJS -  CC FE & UXUnit Testing in AngularJS -  CC FE & UX
Unit Testing in AngularJS - CC FE & UX
Ā 

Similar to Testing Ember Apps

Capybara and cucumber with DSL using ruby
Capybara and cucumber with DSL using rubyCapybara and cucumber with DSL using ruby
Capybara and cucumber with DSL using rubyDeepak Chandella
Ā 
Let's make this test suite run faster
Let's make this test suite run fasterLet's make this test suite run faster
Let's make this test suite run fasterDavid Gageot
Ā 
Austin Web Architecture
Austin Web ArchitectureAustin Web Architecture
Austin Web Architecturejoaquincasares
Ā 
React Component Library Design @WalmartLabs
React Component Library Design @WalmartLabsReact Component Library Design @WalmartLabs
React Component Library Design @WalmartLabschaseadamsio
Ā 
High Performance Serverless Functions in Scala
High Performance Serverless Functions in ScalaHigh Performance Serverless Functions in Scala
High Performance Serverless Functions in ScalaJason Swartz
Ā 
WebNano - Ideas for Web Frameworks
WebNano - Ideas for Web FrameworksWebNano - Ideas for Web Frameworks
WebNano - Ideas for Web Frameworksguestf89f9cb
Ā 
Corwin on Containers
Corwin on ContainersCorwin on Containers
Corwin on ContainersCorwin Brown
Ā 
Beautiful code instead of callback hell using ES6 Generators, Koa, Bluebird (...
Beautiful code instead of callback hell using ES6 Generators, Koa, Bluebird (...Beautiful code instead of callback hell using ES6 Generators, Koa, Bluebird (...
Beautiful code instead of callback hell using ES6 Generators, Koa, Bluebird (...andreaslubbe
Ā 
Designing a play framework application
Designing a play framework applicationDesigning a play framework application
Designing a play framework applicationVulcanMinds
Ā 
Contribute to rails
Contribute to railsContribute to rails
Contribute to railsmartinsvalin
Ā 
Jruby a Pi and a database
Jruby a Pi and a databaseJruby a Pi and a database
Jruby a Pi and a databasePhilipp Fehre
Ā 
Message Queues in Ruby - An Overview
Message Queues in Ruby - An OverviewMessage Queues in Ruby - An Overview
Message Queues in Ruby - An OverviewPradeep Elankumaran
Ā 
Capistrano for non-rubyist
Capistrano for non-rubyistCapistrano for non-rubyist
Capistrano for non-rubyistDimitris Tsironis
Ā 
Stop Being Lazy and Test Your Software
Stop Being Lazy and Test Your SoftwareStop Being Lazy and Test Your Software
Stop Being Lazy and Test Your SoftwareLaura Frank Tacho
Ā 
Function as a Service
Function as a ServiceFunction as a Service
Function as a Servicerich fernandez
Ā 
Using Apache Camel as AKKA
Using Apache Camel as AKKAUsing Apache Camel as AKKA
Using Apache Camel as AKKAJohan Edstrom
Ā 
Java to Scala: Why & How
Java to Scala: Why & HowJava to Scala: Why & How
Java to Scala: Why & HowGraham Tackley
Ā 
Cassandra Development Nirvana
Cassandra Development Nirvana Cassandra Development Nirvana
Cassandra Development Nirvana DataStax
Ā 

Similar to Testing Ember Apps (20)

Capybara and cucumber with DSL using ruby
Capybara and cucumber with DSL using rubyCapybara and cucumber with DSL using ruby
Capybara and cucumber with DSL using ruby
Ā 
Cucumber
CucumberCucumber
Cucumber
Ā 
Let's make this test suite run faster
Let's make this test suite run fasterLet's make this test suite run faster
Let's make this test suite run faster
Ā 
Austin Web Architecture
Austin Web ArchitectureAustin Web Architecture
Austin Web Architecture
Ā 
React Component Library Design @WalmartLabs
React Component Library Design @WalmartLabsReact Component Library Design @WalmartLabs
React Component Library Design @WalmartLabs
Ā 
High Performance Serverless Functions in Scala
High Performance Serverless Functions in ScalaHigh Performance Serverless Functions in Scala
High Performance Serverless Functions in Scala
Ā 
WebNano - Ideas for Web Frameworks
WebNano - Ideas for Web FrameworksWebNano - Ideas for Web Frameworks
WebNano - Ideas for Web Frameworks
Ā 
Corwin on Containers
Corwin on ContainersCorwin on Containers
Corwin on Containers
Ā 
Beautiful code instead of callback hell using ES6 Generators, Koa, Bluebird (...
Beautiful code instead of callback hell using ES6 Generators, Koa, Bluebird (...Beautiful code instead of callback hell using ES6 Generators, Koa, Bluebird (...
Beautiful code instead of callback hell using ES6 Generators, Koa, Bluebird (...
Ā 
Designing a play framework application
Designing a play framework applicationDesigning a play framework application
Designing a play framework application
Ā 
Contribute to rails
Contribute to railsContribute to rails
Contribute to rails
Ā 
Jruby a Pi and a database
Jruby a Pi and a databaseJruby a Pi and a database
Jruby a Pi and a database
Ā 
Message Queues in Ruby - An Overview
Message Queues in Ruby - An OverviewMessage Queues in Ruby - An Overview
Message Queues in Ruby - An Overview
Ā 
Capistrano for non-rubyist
Capistrano for non-rubyistCapistrano for non-rubyist
Capistrano for non-rubyist
Ā 
Stop Being Lazy and Test Your Software
Stop Being Lazy and Test Your SoftwareStop Being Lazy and Test Your Software
Stop Being Lazy and Test Your Software
Ā 
Function as a Service
Function as a ServiceFunction as a Service
Function as a Service
Ā 
TorqueBox
TorqueBoxTorqueBox
TorqueBox
Ā 
Using Apache Camel as AKKA
Using Apache Camel as AKKAUsing Apache Camel as AKKA
Using Apache Camel as AKKA
Ā 
Java to Scala: Why & How
Java to Scala: Why & HowJava to Scala: Why & How
Java to Scala: Why & How
Ā 
Cassandra Development Nirvana
Cassandra Development Nirvana Cassandra Development Nirvana
Cassandra Development Nirvana
Ā 

Recently uploaded

Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024The Digital Insurer
Ā 
Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024The Digital Insurer
Ā 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
Ā 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoffsammart93
Ā 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
Ā 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobeapidays
Ā 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businesspanagenda
Ā 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
Ā 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024The Digital Insurer
Ā 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...DianaGray10
Ā 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdflior mazor
Ā 
Scaling API-first ā€“ The story of a global engineering organization
Scaling API-first ā€“ The story of a global engineering organizationScaling API-first ā€“ The story of a global engineering organization
Scaling API-first ā€“ The story of a global engineering organizationRadu Cotescu
Ā 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUK Journal
Ā 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
Ā 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
Ā 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
Ā 
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...Principled Technologies
Ā 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024The Digital Insurer
Ā 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?Igalia
Ā 

Recently uploaded (20)

Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Ā 
Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024
Ā 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
Ā 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
Ā 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Ā 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
Ā 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Ā 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
Ā 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Ā 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Ā 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Ā 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
Ā 
Scaling API-first ā€“ The story of a global engineering organization
Scaling API-first ā€“ The story of a global engineering organizationScaling API-first ā€“ The story of a global engineering organization
Scaling API-first ā€“ The story of a global engineering organization
Ā 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Ā 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
Ā 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
Ā 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Ā 
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Ā 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
Ā 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
Ā 

Testing Ember Apps

  • 1. Testing Ember Apps Jo Liss https://twitter.com/jo_liss Hi, Iā€™m Jo, Iā€™m on the http://solitr.com/blog Capybara and Konacha core teams, and Iā€™m an Ember contributor. This talk will be more an architectural over view than a tutorial. Iā€™ll assume Rails in some places, but the concepts apply to other backends as well. Slides licensed under CC BY 3.0.
  • 2. This presentation has 2 parts: Part 1: Full-Stack Integration Tests Capybara similar: PhantomJS
  • 3. Part 1: Full-Stack Integration Tests Capybara Part 2: Client-Side Integration Tests Konacha similar: QUnit, Mocha, Jasmine I like to test apps with a combination of Capybara and Konacha tests. I noticed that having a good test suite makes me *much* more productive.
  • 4. Part 1: Full-Stack Integration Tests Capybara Itā€™s not very hard to get Capybara working right. So I want to focus on high-level architecture instead. I think thatā€™s sometimes under- appreciated.
  • 5. Capybara Quick refresher: ā€œSelenium for Railsā€ You can plug in different Q: Who has used Capybara to drivers, like WebKit. All test a JavaScript app? of the following applies -------> to any driver. Q: Who ran into problems with either performance, or flickering tests (brittleness)?
  • 6. Capybara These pains are architectural. These pains are because of the architecture.
  • 7. Capybara These pains are architectural. Performance :-( Brittleness :-( There are probably limits So letā€™s talk about why to how fast you can this happens. make Capybara tests. And you can hunt down flickering tests (and you should), but they will still pop up occasionally.
  • 8. So you have a test suite written in Ruby, and it talks to a DB backend. Test suite DB
  • 9. Firefox + So when you have a Capybara test, Capybara will automatically spin up a Selenium Firefox for you, and your test suite will send requests to that Firefox. Test suite But Selenium commands are mostly non-blocking, i.e. they return before they finish. So when you have a DB sequence of commands, even with Ajax, Capybara does some intelligent polling to make them appear synchronous. This works transparent 99% of the time, and it makes for very readable test code, but very occasionally, youā€™ll end up with a race condition, and then you have to understand whatā€™s going on underneath. So let me double that line to indicate that itā€™s async.
  • 10. So who does the Firefox make Firefox + HTTP requests to? Clearly, Ruby is busy with the test suite. Selenium Capybara actually spins up another ser ver thread. Test suite DB
  • 11. Firefox + Selenium Server Test suite So now Firefox has a server to load the pages DB from. If thereā€™s Ajax requests, this whole thing becomes asynchronous. So thatā€™s another source of race conditions. Let me double that line...
  • 12. Firefox + Selenium Server Test suite And of course the server talks to the database -- DB another line...
  • 13. Firefox + Selenium Server Test suite Which means you also This is clearly fundamentally quite complex have to be careful not to have the t wo Ruby DB and error-prone. threads interfere with Iā€™m not trying to convince you that Capybara each other while they is a bad tool. But I think itā€™s actually useful to access the database. understand this architecture. By the way, just to be clear, thatā€™s not Seleniumā€™s fault. If you drop in WebKit or PhantomJS into Capybara, it suffers from the same issues.
  • 14. Firefox + Selenium At the moment, this kind of architecture is the only solution to give us a full-stack integration test, database to DOM. So itā€™s actually very useful. Server If you donā€™t use Rails, Iā€™d definitely Test suite recommend finding a comparable solution, or hand-rolling one. DB
  • 15. Capybara Powerful but clunky So one solid strategy ...
  • 16. ... is limiting yourself to exercising one happy path for Capybara each model, to make sure that stuff in the DB ends up in the DOM, and vice versa. Powerful but clunky Strategy: Only test every model once DB-to-DOM, read and write
  • 17. And then we can use pure client- side integration testing to get Capybara more fine-grained testing. Powerful but clunky Strategy: Only test every model once DB-to-DOM, read and write Move ļ¬ner-grained tests to client side
  • 18. Part 2: Client-Side Integration Tests with Konacha The idea is to limit the architectural complexity. No backend server, no DB, test runs directly in the browser, not in a separate process. This makes it faster, and extremely reliable.
  • 19. Konacha Rails gem packaging Konacha is pretty Mocha.js testing framework + simple, so if youā€™re not on Rails, you can easily hand-roll an equivalent test setup. Chai.js assertion lib Let me show you what Mocha and Chai do...
  • 20. Mocha + Chai describe 'todo list', -> it 'can add items', -> Mocha is a testing framework, like QUnit or Jasmine, or RSpec on Ruby. But Mocha doesnā€™t do assertions, so you typically combine it with the Chai assertion library.
  • 21. Mocha + Chai describe 'todo list' -> it 'can add items', -> ... $('.todo').should .contain 'Buy milk'
  • 22. Interlude: Konacha Video Before I go on, let me show you what weā€™re trying to achieve. http://www.youtube.com/watch?v=heK78M6Ql9Q So we basically just hit Cmd+R on Konachaā€™s development ser ver. Konacha automatically runs your tests in an iframe, and loads your application.css. Thatā€™s also really easy to do yourself if you donā€™t use Rails with Konacha. This is also really useful to ramp up people to Ember, because you can visually see what your test does. And if a test fails, you can just click into the iframe and interact with the application.
  • 23. Konacha In the browser (Cmd+R) for dev rake task for CI CI task through Capybara
  • 24. Why is Konacha fast? No page loads You donā€™t have to serve and parse the entire stack of assets for every test case.
  • 25. Why is Konacha fast? No page loads 100% synchronous No polling, no waiting.
  • 26. Why is Konacha fast? No page loads 100% synchronous No stack Most expensive thing is the DOM.
  • 27. Unit vs. Integration What you just saw I call ā€œclient-side integration testsā€. They donā€™t involve the backend, but on the frontend, they exercise the entire Ember app.
  • 28. Unit vs. Integration Lots of simple layers ==> integration tests win. On Ember, I avoid unit tests. The reason is, the individual layers of an Ember app are very simple. What I care about is whether they play together. Unit tests tend to be very ā€œweakā€, i.e. theyā€™ll just keep passing even when your app Okay, breadā€™nā€™butter breaks. time. As a rule of thumb, I tend to do zero unit testing for Ember apps.
  • 29. Ember setup No ā€œofļ¬cialā€ support for testing. So we wing it. A bunch of pieces are missing to make this easy like with Rails. (Notably, good fixture handling, package manager, ...) Hereā€™s some practical tips:
  • 30. Thereā€™s no repeated app instantiation yet, so I like to start up the Starting the app application at the beginning of the entire test suite.
  • 31. Starting the app # Parse time: We call App.deferReadiness, and advance readiness it App.deferReadiness() once you want the app to run. # Global before all: before -> UPDATE Feb 26 2013: App.advanceReadiness() Instead you can now Enable Ember.testing *before* parsing your app code, and kick it off with ā€œbefore -> App.initialize()ā€; no more advanceReadiness.
  • 32. Router We tell the router not to mess with the URL. App.Router.reopen location: 'none'
  • 33. Router App.Router.reopen location: 'none' beforeEach: -> App.router.transitionTo('...') Before each test, UPDATE Feb 26 2013: transition back to the root state. You can now use ā€œbeforeEach -> This is a pretty hackish App.reset()ā€. way to reset app state, but for now itā€™s surprisingly reliable.
  • 34. Reset store beforeEach -> App.store.destroy() if App.store App.store = DS.Store.create()
  • 35. Konacha: Keep body Konacha.reset = function() { } Konacha by default cleans the <body> element before each test. But our app keeps running bet ween tests, so we disable this by nuking Konacha.reset.
  • 36. Runloop & setTimeout Ember automatically schedules runloops with setTimeout. But setTimeout is Ember.testing = true the enemy of deterministic tests. So we disable automatic runloop creation by enabling the Ember.testing flag. You want to put this before loading (parsing) your app modules.
  • 37. Runloop & setTimeout Ember.testing = true Itā€™s OK to have Em.run everywhere: Em.run => foo.set ... Em.run => $(...).click() Most actions have their effects deferred to the end of the runloop. In test code you need the effects immediately, so you wrap things in Ember.run. Looks funny, but itā€™s nothing to worry about. :-)
  • 38. Animations jQuery.fx.off = true Nothing like this for D3. :-( This is not Ember-related, but you donā€™t want animations, because they are asynchronous. For D3,, this may require support in your production code. :-( Probably the trickiest thing is data fixtures:
  • 39. Model Fixtures 1. Client-side ļ¬xtures. You have a choice whether you write them in JavaScript or 2. Server-side ļ¬xtures. generate them from the server side, and itā€™s kind of a trade off.
  • 40. (1) Client-Side Fixtures FixtureAdapter (immature) App.TodoList.FIXTURES = [ { ... }, { ... } For client-side fixtures, ] there is a FixtureAdapter in Ember. It still needs some love, but we can probably get it there pretty soon. And basically you just define an array of fixtures for every model.
  • 42. (1) Client-Side Fixtures :-) Easy :-( Goes out of sync with backend But you donā€™t know if your fixtures actually represent the reality of your backend.
  • 43. (1) Client-Side Fixtures :-) Easy :-( Goes out of sync with backend :-( Fragile You can even have bugs in your fixtures, where you donā€™t set up bidirectional belongsTo and hasMany relationships properly.
  • 44. (1) Client-Side Fixtures :-) Easy :-( Goes out of sync with backend :-( Fragile :-( Server-side computed attributes JavaScript is still not very powerful. Oftentimes itā€™s So the alternative to all easier in practice to implement computed properties on the this is... backend side and ser ve them out as read-only attributes. In one backend I worked on, half of the properties were DB columns, and half were just methods on the Rails models. Trying to keep these properties manually updated in your fixture data is obviously painful.
  • 45. (2) Server-Side Fixtures rake test:fixtures 1. Write ļ¬xtures to DB 2. Generate JSON to ļ¬xtures.js
  • 46. (2) Server-Side Fixtures rake test:fixtures 1. Write ļ¬xtures to DB 2. Generate JSON to ļ¬xtures.js Load through RESTAdapter Load that data in fixtures.js before every test case, perhaps using your RESTAdapter so you translate the JSON correctly.
  • 47. (2) Server-Side Fixtures :-) Covers models, serializers, adapter with no speed penalty
  • 48. (2) Server-Side Fixtures :-) Covers models, serializers, adapter :-) Easy to maintain Compact definitions, esp. w/ FactoryGirl; stuff doesnā€™t go out of sync.
  • 49. (2) Server-Side Fixtures :-) Covers models, serializers, adapter :-) Easy to maintain :-( Usability Generated fixtures file can go stale and you have to regenerate. Itā€™s not bad, just bothersome.
  • 50. (2) Server-Side Fixtures :-) Covers models, serializers, adapter :-) Easy to maintain :-( Usability :-( Complex to set up Work to set up. You end up with some custom code, and it ties tightly into backend. I personally think itā€™s generally worth it, but it also depends on your specific app.
  • 51. Fixture Woes Global ļ¬xtures :-( Both of these techniques mean that you have the same fixture set for the entire test suite. want FactoryGirl Ideally weā€™d build something like FactoryGirl, but I donā€™t think weā€™re quite there yet.
  • 52. Bonus: JS-driven? Capybara but in JavaScript? One thing that sometimes comes up is, can we have a full-stack integration test written in JavaScript?
  • 53. Firefox + So instead of having the Selenium Test suite written in Ruby... Server Test suite DB
  • 54. Firefox w/ JS tests ... we push them into the browser, and so we avoid the t wo-threaded problem. Server I think that would be really awesome -- and the truth is, we just donā€™t have the tooling yet to make that work easily. Perhaps the biggest hurdle DB is that we donā€™t have a way to reset the database, add fixtures, and perhaps query database records from JavaScript. But it is probably a good direction to move towards
  • 55. Q &A Notes from the talk, thanks to @cgcardona: Q: With Konacha do you see opportunity for TTD? A: Not quite TDD (hard with visual stuff), but continuous. When working with Konacha I wrote tests as I went. Q: Can you test views in isolation? A: Itā€™s really tricky to instantiate a view in isolation, Ember wants a whole appā€¦ Itā€™s too ā€˜unit testyā€™. It might be possible.
  • 56. Q &A Comment: We use ā€˜Rosieā€™ (https://github.com/bkeepers/ rosie) for Javascript factories. Comment: Have you tried VCR for server side things? Itā€™s a Ruby library that will record request responses so you can play them back later. We run VCR against a live production server and generate response data that the tests use.
  • 57. Q &A Q: A lot of bugs come from asynchronicity. Have you tried to test that speciļ¬cally? A: No I havenā€™t. My hope is that a lot of these bugs disappear with ember-data. Mocha allows for asynchronous tests where you set a callback for when your test is complete.