Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

root/branches/1-2-stable/activerecord/RUNNING_UNIT_TESTS

Revision 5228, 2.3 kB (checked in by bitsweat, 2 years ago)

Update RUNNING_UNIT_TESTS for current Rake tasks. Closes #6349.

Line 
1 == Creating the test database
2
3 The default names for the test databases are "activerecord_unittest" and
4 "activerecord_unittest2". If you want to use another database name then be sure
5 to update the connection adapter setups you want to test with in
6 test/connections/<your database>/connection.rb.
7 When you have the database online, you can import the fixture tables with
8 the test/fixtures/db_definitions/*.sql files.
9
10 Make sure that you create database objects with the same user that you specified in
11 connection.rb otherwise (on Postgres, at least) tests for default values will fail.
12
13 == Running with Rake
14
15 The easiest way to run the unit tests is through Rake. The default task runs
16 the entire test suite for all the adapters. You can also run the suite on just
17 one adapter by using the tasks test_mysql, test_sqlite, test_postgresql or any
18 of the other test_ tasks. For more information, checkout the full array of rake
19 tasks with "rake -T"
20
21 Rake can be found at http://rake.rubyforge.org
22
23 == Running by hand
24
25 Unit tests are located in test directory. If you only want to run a single test suite,
26 or don't want to bother with Rake, you can do so with something like:
27
28    cd test; ruby -I "connections/native_mysql" base_test.rb
29    
30 That'll run the base suite using the MySQL-Ruby adapter. Change the adapter
31 and test suite name as needed.
32
33 You can also run all the suites on a specific adapter with:
34
35    cd test; all.sh "connections/native_mysql"
36
37 == Faster tests
38
39 If you are using a database that supports transactions, you can set the
40 "AR_TX_FIXTURES" environment variable to "yes" to use transactional fixtures.
41 This gives a very large speed boost. With rake:
42
43   rake AR_TX_FIXTURES=yes
44
45 Or, by hand:
46
47   AR_TX_FIXTURES=yes ruby -I connections/native_sqlite3 base_test.rb
48
49 == Testing with Oracle
50
51 In order to allow for testing against Oracle using an "arunit" schema within an existing
52 Oracle database, the database name and tns connection string must be set in environment
53 variables prior to running the unit tests.
54
55   $ export ARUNIT_DB_NAME=MYDB
56   $ export ARUNIT_DB=MYDB
57
58 The ARUNIT_DB_NAME variable should be set to the name by which the database knows
59 itself, ie., what will be returned by the query:
60
61   select sys_context('userenv','db_name') db from dual
62
63 And the ARUNIT_DB variable should be set to the tns connection string.
64
Note: See TracBrowser for help on using the browser.