Integration Testing the Events Application in Font

Maker QR Code in Font Integration Testing the Events Application

Integration Testing the Events Application
QR Code ISO/IEC18004 Generator In None
Using Barcode maker for Font Control to generate, create QR Code image in Font applications.
www.OnBarcode.com
Barcode Maker In None
Using Barcode creation for Font Control to generate, create Barcode image in Font applications.
www.OnBarcode.com
Let s get started by generating the test. Given that Rails ships with a generator for just about everything, it shouldn t surprise you that it also includes one for generating integration tests. It works just like the others you ve already used.
Generate Code 128A In None
Using Barcode generation for Font Control to generate, create ANSI/AIM Code 128 image in Font applications.
www.OnBarcode.com
USS Code 39 Encoder In None
Using Barcode generator for Font Control to generate, create Code 39 Full ASCII image in Font applications.
www.OnBarcode.com
$ ./script/generate integration UserStories
Printing Barcode In None
Using Barcode creator for Font Control to generate, create Barcode image in Font applications.
www.OnBarcode.com
EAN-13 Supplement 5 Creator In None
Using Barcode creator for Font Control to generate, create European Article Number 13 image in Font applications.
www.OnBarcode.com
exists create
Drawing Data Matrix 2d Barcode In None
Using Barcode generation for Font Control to generate, create DataMatrix image in Font applications.
www.OnBarcode.com
GTIN - 12 Creation In None
Using Barcode generator for Font Control to generate, create GTIN - 12 image in Font applications.
www.OnBarcode.com
test/integration/ test/integration/user_stories_test.rb
Scan QR Code JIS X 0510 In Visual C#
Using Barcode recognizer for Visual Studio .NET Control to read, scan read, scan image in .NET applications.
www.OnBarcode.com
Draw QR Code In Visual Studio .NET
Using Barcode creator for ASP.NET Control to generate, create QR Code image in ASP.NET applications.
www.OnBarcode.com
Open the newly generated file and take a peek, as shown in Listing 9-17.
vba barcode generator excel
Using Barcode maker for Excel Control to generate, create PDF 417 image in Microsoft Excel applications. vba barcode generator excel
www.OnBarcode.com
Scanning UCC - 12 In VB.NET
Using Barcode recognizer for .NET framework Control to read, scan read, scan image in VS .NET applications.
www.OnBarcode.com
Listing 9-17. User Stories Test in test/integration/user_stories_test.rb
Matrix 2D Barcode Drawer In .NET
Using Barcode generation for ASP.NET Control to generate, create Matrix image in ASP.NET applications.
www.OnBarcode.com
PDF417 Decoder In None
Using Barcode scanner for Software Control to read, scan read, scan image in Software applications.
www.OnBarcode.com
require "#{File.dirname(__FILE__)}/../test_helper" class UserStoriesTest < ActionController::IntegrationTest # fixtures :your, :models # Replace this with your real tests. def test_truth assert true end end
Decode DataMatrix In None
Using Barcode decoder for Software Control to read, scan read, scan image in Software applications.
www.OnBarcode.com
Create Barcode In .NET
Using Barcode generation for Reporting Service Control to generate, create Barcode image in Reporting Service applications.
www.OnBarcode.com
At this stage, it looks a lot like the other test files you ve seen so far. Notice, however, that it s a subclass of ActionController::IntegrationTest. That s about the only difference, but not for long. First, we need to get our fixtures in place. We ll use both the users and events fixtures for this test, so load them immediately inside the class body.
Recognize QR Code JIS X 0510 In Java
Using Barcode reader for Java Control to read, scan read, scan image in Java applications.
www.OnBarcode.com
Barcode Decoder In Java
Using Barcode scanner for Java Control to read, scan read, scan image in Java applications.
www.OnBarcode.com
fixtures :users, :events
EAN13 Creation In None
Using Barcode printer for Word Control to generate, create GTIN - 13 image in Office Word applications.
www.OnBarcode.com
Encode GS1 128 In Visual Studio .NET
Using Barcode maker for Visual Studio .NET Control to generate, create USS-128 image in .NET applications.
www.OnBarcode.com
Test cases are added to integration tests in exactly the same way as unit and functional test cases are added: as methods prefixed with test_. Integration test cases tend to look deceptively like functional tests, but they have a few subtle differences, which we ll point out as we add them. Listing 9-18 shows a test case that goes through the process of logging in a user.
CHAPTER 9 TESTING YOUR APPLICATION
Listing 9-18. Login Integration Test, in test/integration/user_stories_test.rb
def test_should_login_user_and_redirect get '/login' assert_response :success assert_template 'login' post '/login', :login => 'eugene', :password => 'secret' assert_response :redirect assert_redirected_to :controller => 'events' follow_redirect! assert_response :success assert_template 'index' assert session[:user_id] end
Notice how when our response is a redirect, we re able to follow it, even when it redirects to another controller. The follow_redirect! method does exactly what you might think: it lets you follow a single redirect response, as long as the last response was, in fact, a redirect. If the last response wasn t a redirect, an exception will be raised. Let s add a test case for the logout action as well, as shown in Listing 9-19.
Listing 9-19. Logout Integration Test, in test/integration/user_stories_test.rb
def test_should_logout_user_and_redirect get '/logout' assert_response :redirect assert_nil session[:user] follow_redirect! assert_template 'login' end
Again, we re able to follow the redirect and test that the correct template was rendered.
CHAPTER 9 TESTING YOUR APPLICATION
Let s get a little fancier by testing that we can log in, create a new event, and log out, all in a single test. We ll combine the login and logout tests we ve already written and sandwich an events creation test in the middle, as shown in Listing 9-20.
Listing 9-20. Event Creation Integration Test, in test/integration/user_stories_test.rb
def test_should_login_create_event_and_logout get '/login' assert_response :success assert_template 'login' post '/login', :login => 'eugene', :password => 'secret' assert_response :redirect assert_redirected_to :controller => 'events' follow_redirect! assert_response :success assert_template 'index' assert session[:user_id] get '/events/new' assert_response :success assert_template 'new' post '/events/create', :event => {:title => 'BBQ', :location => 'My back yard'} assert assigns(:event).valid assert_response :redirect assert_redirected_to :action => 'list' follow_redirect! assert_response :success assert_template 'index' get '/logout' assert_response :redirect
CHAPTER 9 TESTING YOUR APPLICATION
assert_redirected_to :action => 'login' assert_nil session[:user] follow_redirect! assert_template 'login' end
Here s what we get when we run the test.
user_stories_test.rb
Loaded suite /usr/local/rake/rake_test_loader Started . Finished in 0.248968 seconds. 1 tests, 19 assertions, 0 failures, 0 errors
Great 19 assertions, and we know that we ve just tested the whole stack from dispatcher to database. Not too shabby, is it If you re thinking that what we ve just done looks a lot like we re telling a story (Eugene logs in, Eugene creates event, Eugene logs out), you would be right.
Story-Based Testing
Integration tests are great for creating story-based scenarios using a domain-specific language (DSL). They even go so far as to allow you to test multiple users interacting! What do we mean by story-based tests Well, what if we could do something like this:
def test_creating_an_event eugene = registered_user eugene.logs_in 'eugene', 'secret' eugene.creates_event eugene.logs_out end
Here, we re telling an easy-to-understand story that requires no programming knowledge to follow. Eugene logs in and proceeds to create a new event. When he is finished, he logs out. Behind the scenes, we can test every request, response, and redirect, following
Copyright © OnBarcode.com . All rights reserved.