Testing Carol Wolf Computer Science. Testing built into Rails  Rails comes with three databases.  development  test  production  The test database.

Slides:



Advertisements
Similar presentations
XML-XSL Introduction SHIJU RAJAN SHIJU RAJAN Outline Brief Overview Brief Overview What is XML? What is XML? Well Formed XML Well Formed XML Tag Name.
Advertisements

The Librarian Web Page Carol Wolf CS396X. Create new controller  To create a new controller that can manage more than just books, type ruby script/generate.
Html: getting started HTML is hyper text markup language. It is what web browsers look at on the Internet. HTML documents should be created in a simple.
CS 142 Lecture Notes: Rails Controllers and ViewsSlide 1 Simple Rails Template
28-Apr-15 Unit Testing in Rails Testing Database Actions.
Creating Web Services with Ruby on Rails Robert Thew Internet and Web Systems II.
NMD202 Web Scripting Week5. What we will cover today PHPmyAdmin Debugging – using print_r Modifying Data PHP (cont.) 4D Methodology File and IO operations.
What is MySQL? MySQL is a relational database management system (A relational database stores data in separate tables rather than putting all the data.
Creating and Managing RSS Feeds Kate Pitcher SUNY Geneseo © 2005
Creating Web Services with Ruby on Rails Robert Thew Internet and Web Systems II.
CS 683 Emerging Technologies Fall Semester, 2005 Doc 23 Rails Model Example Nov 17, 2005 Copyright ©, All rights reserved SDSU & Roger Whitney, 5500.
A complete ror application. Some easy tutorials This uses oracle but it is easy to replace that with mysql:
Creating a wiki blog. Run apps that come with instant rails distribution select I /rails applications/open ruby console window Cd to cookbook or typo.
Ruby on Rails Creating a Rails Application Carol E Wolf CS396X.
Concordia University Department of Computer Science and Software Engineering Click to edit Master title style ADVANCED PROGRAMING PRACTICES API documentation.
Application Development Description and exemplification of server-side scripting language for server connection, database selection, execution of SQL queries.
1Computer Sciences Department Princess Nourah bint Abdulrahman University.
Chapter 3.2 – RoR: easier, faster, better Maciej Mensfeld Presented by: Maciej Mensfeld RoR: easier, faster, better mensfeld.pl github.com/mensfeld.
1 Dr Alexiei Dingli Web Science Stream Models, Views and Controllers.
CREATED BY ChanoknanChinnanon PanissaraUsanachote
Web Application Programming Carol Wolf Computer Science.
Ajax and Ruby on Rails Session 9 INFM 603.
Views Carol Wolf Computer Science. Extended Ruby  Views files are written in extended Ruby, erb.  They end in.html.erb.  Ruby code is intermixed with.
Multifarious Project Team Members Alberto Dominguez Nirmit Gang Jimmy Garcia Javier Handal.
1 Dr Alexiei Dingli Web Science Stream Advanced ROR.
These Questions are copied from
CIS 451: Introduction to XML Dr. Ralph D. Westfall October, 2011.
Username Password Enter Username and Password Login.
1 Dr Alexiei Dingli Web Science Stream Introducing Rails.
JavaDoc1 JavaDoc DEPARTMENT OF COMPUTER SCIENCE AND SOFTWARE ENGINEERING CONCORDIA UNIVERSITY July 24, 2006 by Emil Vassev & Joey Paquet revision 1.2 –
Electronic Commerce COMP3210 Session 4: Designing, Building and Evaluating e-Commerce Initiatives – Part II Dr. Paul Walcott Department of Computer Science,
Ruby on Rails Your first app. Rails files app/ Contains the controllers, models, views and assets for your application. You’ll focus on this folder for.
Installing and Using MySQL and phpMyAdmin. Last Time... Installing Apache server Installing PHP Running basic PHP scripts on the server Not necessary.
Ruby on Rails CSE 190M, Spring 2009 Week 6. Overview How to use a database Demo creating a blog application on Rails Explain how the application works.
Ruby on Rails: Databases. Rails Database Familiar Table Concept Naming convention – lower case, plural (i.e. tweets) How to Access (find), Update, Delete.
WEB APPLICATION DEVELOPMENT For More visit:
1 CS 3870/CS 5870: Note 07 Lab 3 Lab 4 Test 1: Two Tables.
Web Technologies COMP6115 Session 4: Adding a Database to a Web Site Dr. Paul Walcott Department of Computer Science, Mathematics and Physics University.
Lecture: Web Design Assis. Prof. Freshta Hanif Ehsan Faculty of Computer Science Kabul Polytechnic University Spring Semester
 Go to YouTube and click “create account” on the top right of the page.YouTube  If you already have a Google account (i.e. gmail) then you may use this.
1 Bulk Loading Documents* into Windchill (Screen captures from Windchill 10.1 M040) Note: All for WTDocument Type (includes MS Word, Autocad, pdf, etc.)
Studio Fx on Rails Demonstrating the Studio Fx API.
MySQL Getting Started BCIS 3680 Enterprise Programming.
XML. HTML Before you continue you should have a basic understanding of the following: HTML HTML was designed to display data and to focus on how data.
Adding Data to a Database Table Carol Wolf Computer Science.
State the Medical Research Topic Give a short description of the purpose of the research topic and what the teaching materials will cover.
OpenMRS Create New Module.
The Controller Carol Wolf Computer Science. Rails generate commands  Using the generate command, you can create a number of useful objects.  Rails:
Migrations Carol Wolf CS 396X. ISBNTitleAuthorImage EmmaAustenemma.jpg Oliver TwistDickenstwist.jpg HamletShakespearehamlet.jpg.
Introduction lab1. Suzanne J. Sultan 2 What is HTML? The definition of HTML is Hyper Text Markup Language. HTML is a computer language devised to allow.
VCE IT Theory Slideshows by Mark Kelly study design By Mark Kelly, vceit.com, Begin.
In the Name Of Almighty Allah. Java Application Connection To Mysql Created by Hasibullah (Sahibzada) Kabul Computer Science Faculty Afghanistan.
MySQL Getting Started BCIS 3680 Enterprise Programming.
Using XML. The Ticket Booth System We need a way to retain information between program runs. In real life, we would probably use a database system for.
Basic Setup of OpenMeetings Version Three Styles for Setup Style1 : Starting from Scratch – Starting from svn check out and compiling with ant.
Flash Board MX PHP Files CISC 254. Fix for Global Variables foreach($HTTP_GET_VARS as $name => $value) { $$name = $value;} foreach($HTTP_POST_VARS as.
The Bookstore Problem. Contents I.Problem Description II.Solution III.Exercise.
Bulk Loading Documents* into Windchill
Web Design and Development
Using Access and the Web
Microsoft Office Illustrated
Database Driven Websites
Bruce Scharlau, University of Aberdeen, 2017
Presentation Title Presentation Title Presentation Title
What is XML?.
Put the title here Here is the sub-title.
Put the title here Here is the sub-title.
Sample Source Note Card for Book with one author
End-of-Book Reflection
Presentation transcript:

Testing Carol Wolf Computer Science

Testing built into Rails  Rails comes with three databases.  development  test  production  The test database does not contain your important data.  It can be filled and emptied without causing problems.  Run with rake test.  Described in config/database.yml  yml is short for yaml  yaml stands for yaml ain’t markup language  yaml is simpler than xml  It shares the descriptive purpose of xml  An example is on the next page.

development: adapter: sqlite3 database: db/development.sqlite3 pool: 5 timeout: 5000 test: adapter: sqlite3 database: db/test.sqlite3 pool: 5 timeout: 5000 production: adapter: sqlite3 database: db/production.sqlite3 pool: 5 timeout: 5000

config/database.yml for MySql development: adapter: mysql2 encoding: utf8 database: name_development pool: 5 username: root password: mypassword socket: /tmp/mysql.sock

test folder  Each application has a test folder.  Sub folders  fixtures – used for sample data  functional – tests the controller  integration – tests interacting controllers  performance – benching and profiling  unit – tests for models  The scaffold command populates all the sub folders except for integration.  An example is on the next slide.

fixtures/books.yml # Read about fixtures at one: isbn: MyString author: MyString title: MyString two: isbn: MyString author: MyString title: MyString

Fixtures  When testing with rake test  Empties test database  Loads fixtures data  Puts fixtures data in a variable for saving  Fixtures are in the form of hashes  Can write: books(:Dickens).title  Fixtures can include ERB  Specific tests can be run using rake test:fixtures, rake test:functionals, etc.

Unit Tests  Unit tests are used for models, i.e. database tables.  They contain assertions  assert book.invalid?  assert book.errors[:isbn].any?  The names in quotes will be replaced by names with underscores. require 'test_helper' class BookTest < ActiveSupport::TestCase # Replace this with your real tests. test "the truth" do assert true end

Replace book_test.rb with following: require 'test_helper' class BookTest < ActiveSupport::TestCase # Replace this with your real tests. test “book attributes may not be empty" do book = Book.new assert book.invalid? assert book.errors[:isbn].any? assert book.errors[:author].any? assert book.errors[:title].any? end

Functional tests  Used to test controllers  book_controller_test.rb contains tests for each method in the book controller  Below the test for the create method.  Its parameters are sent with a post method test "should create book" do assert_difference(‘Book.count') do post :create, :book end assert_redirected_to book_path(assigns(:book)) end

Our book_controller_test.rb test "should create book" do assert_difference('Book.count') do post :create, :book => { :isbn => '2345', :title => 'Emma', :author => 'Austen‘ } end assert_redirected_to book_path(assigns(:book)) end