2013/06/22

Redmine プラグインのテストが実行できるまで

Redmineのプラグインのテストが実行できるまでのメモ。意外と苦労した。

環境はこちら。
  • Ruby 2.0.0-p195(use rbenv)
  • Redmine 2.3.1
  • Mac OS X 10.8.4

まずは、公式を参考に実行。

% bundle exec rake test:engines:all
rake aborted! Don't know how to build task 'test:engines:all' ...

タスクが存在していないみたいなので、テストに関連しそうなタスクの一覧を確認。

% bundle exec rake -T | grep test
rake ci # Run the Continous Integration tests for Redmine rake extract_fixtures # Create YAML test fixtures from data in an existing database. rake redmine:email:test[login] # Send a test email to the user with the provided login name rake redmine:plugins:test # Runs the plugins tests. rake redmine:plugins:test:functionals # Run tests for {:functionals=>"db:test:prepare"} rake redmine:plugins:test:integration # Run tests for {:integration=>"db:test:prepare"} rake redmine:plugins:test:units # Run tests for {:units=>"db:test:prepare"} rake test # Runs test:units, test:functionals, test:integration together (also available: test:benchmark, test:profile, test:plugins) rake test:coverage # Measures test coverage rake test:rdm_routing # Run tests for rdm_routing / Run the routing tests rake test:recent # Run tests for {:recent=>"test:prepare"} / Test recent changes rake test:scm # Run unit and functional scm tests rake test:scm:functionals # Run tests for {:functionals=>"db:test:prepare"} / Run the scm functional tests rake test:scm:setup:all # Creates all test repositories rake test:scm:setup:bazaar # Creates a test bazaar repository rake test:scm:setup:create_dir # Creates directory for test repositories rake test:scm:setup:cvs # Creates a test cvs repository rake test:scm:setup:darcs # Creates a test darcs repository rake test:scm:setup:filesystem # Creates a test filesystem repository rake test:scm:setup:git # Creates a test git repository rake test:scm:setup:mercurial # Creates a test mercurial repository rake test:scm:setup:subversion # Creates a test subversion repository rake test:scm:units # Run tests for {:units=>"db:test:prepare"} / Run the scm unit tests rake test:scm:update # Updates installed test repositories rake test:single # Run tests for {:single=>"test:prepare"} rake test:ui # Run tests for {:ui=>"db:test:prepare"} / Run the UI tests with Capybara (PhantomJS listening on port 4444 is required) rake test:uncommitted # Run tests for {:uncommitted=>"test:prepare"} / Test changes since last checkin (only Subversion and Git)

どうやら、rake redmine:plugins:test{functionals,integration,units}あたりでテストが出来そう。

% bundle exec rake redmine:plugins:test
rake aborted! undefined method `[]' for nil:NilClass … Tasks: TOP => db:test:load => db:test:purge

RAILS_ENV=test を忘れていた。

% bundle exec rake redmine:plugins:test RAILS_ENV=test
*** Mocha deprecation warning: Change `require 'mocha'` to `require 'mocha/setup'`. rake aborted! database configuration does not specify adapter … Tasks: TOP => redmine:plugins:test:units => db:test:prepare => db:abort_if_pending_migrations => environment

テスト用のデータベースの設定がしてない。 config/database.yml を編集して・・・

# config/databse.yml
development:
  adapter: sqlite3
  database: db/redmine.db

# ここから追加
test:
  adapter: sqlite3
  database: db/redmine_test.db

再度実行。

% bundle exec rake redmine:plugins:test RAILS_ENV=test
*** Mocha deprecation warning: Change `require 'mocha'` to `require 'mocha/setup'`. You have 221 pending migrations: 1 Setup 2 IssueMove 3 IssueAddNote 4 ExportPdf … Run `rake db:migrate` to update your database then try again.

マイグレーションができていないのね。

% bundle exec rake db:migrate RAILS_ENV=test
== Setup: migrating ========================================================== -- create_table("attachments", {:force=>true}) -> 0.0039s -- create_table("auth_sources", {:force=>true}) -> 0.0011s -- create_table("custom_fields", {:force=>true}) -> 0.0008s -- create_table("custom_fields_projects", {:id=>false, :force=>true}) -> 0.0004s -- create_table("custom_fields_trackers", {:id=>false, :force=>true}) -> 0.0413s -- create_table("custom_values", {:force=>true}) -> 0.0011s -- create_table("documents", {:force=>true}) -> 0.0008s -- add_index("documents", ["project_id"], {:name=>"documents_project_id"}) -> 0.0003s -- create_table("enumerations", {:force=>true}) -> 0.0005s -- create_table("issue_categories", {:force=>true}) -> 0.0005s -- add_index("issue_categories", ["project_id"], {:name=>"issue_categories_project_id"}) -> 0.0002s -- create_table("issue_histories", {:force=>true}) -> 0.0007s -- add_index("issue_histories", ["issue_id"], {:name=>"issue_histories_issue_id"}) -> 0.0002s -- create_table("issue_statuses", {:force=>true}) -> 0.0006s -- create_table("issues", {:force=>true}) -> 0.0011s -- add_index("issues", ["project_id"], {:name=>"issues_project_id"}) -> 0.0002s -- create_table("members", {:force=>true}) -> 0.0006s -- create_table("news", {:force=>true}) -> 0.0007s -- add_index("news", ["project_id"], {:name=>"news_project_id"}) -> 0.0002s -- create_table("permissions", {:force=>true}) -> 0.0007s -- create_table("permissions_roles", {:id=>false, :force=>true}) -> 0.0004s -- add_index("permissions_roles", ["role_id"], {:name=>"permissions_roles_role_id"}) -> 0.0002s -- create_table("projects", {:force=>true}) -> 0.0008s -- create_table("roles", {:force=>true}) -> 0.0004s -- create_table("tokens", {:force=>true}) -> 0.0006s -- create_table("trackers", {:force=>true}) -> 0.0005s -- create_table("users", {:force=>true}) -> 0.0009s -- create_table("versions", {:force=>true}) -> 0.0007s -- add_index("versions", ["project_id"], {:name=>"versions_project_id"}) -> 0.0002s -- create_table("workflows", {:force=>true}) -> 0.0006s == Setup: migrated (0.1067s) ================================================= … == RemoveIssuesDefaultFkValues: migrating ==================================== -- change_column_default(:issues, :tracker_id, nil) -> 0.0257s -- change_column_default(:issues, :project_id, nil) -> 0.0737s -- change_column_default(:issues, :status_id, nil) -> 0.0252s -- change_column_default(:issues, :assigned_to_id, nil) -> 0.0236s -- change_column_default(:issues, :priority_id, nil) -> 0.0245s -- change_column_default(:issues, :author_id, nil) -> 0.0251s == RemoveIssuesDefaultFkValues: migrated (0.1981s) =========================== % bundle exec rake redmine:load_default_data RAILS_ENV=test Select language: ar, az, bg, bs, ca, cs, da, de, el, en, en-GB, es, et, eu, fa, fi, fr, gl, he, hr, hu, id, it, ja, ko, lt, lv, mk, mn, nl, no, pl, pt, pt-BR, ro, ru, sk, sl, sq, sr, sr-YU, sv, th, tr, uk, vi, zh, zh-TW [en] ja ==================================== Default configuration data loaded.

もう一度実行。

% bundle exec rake redmine:plugins:test RAILS_ENV=test
*** Mocha deprecation warning: Change `require 'mocha'` to `require 'mocha/setup'`. /Users/pinzolo/.rbenv/versions/2.0.0-p195/bin/ruby -I"lib:test" -I"/Users/pinzolo/projects/sample_plugin/redmine-2.3.1/vendor/bundle/ruby/2.0.0/gems/rake-10.0.4/lib" "/Users/pinzolo/projects/sample_plugin/redmine-2.3.1/vendor/bundle/ruby/2.0.0/gems/rake-10.0.4/lib/rake/rake_test_loader.rb" "plugins/*/test/unit/**/*_test.rb" *** Mocha deprecation warning: Change `require 'mocha'` to `require 'mocha/setup'`. /Users/pinzolo/projects/sample_plugin/redmine-2.3.1/lib/SVG/Graph/Graph.rb:3: warning: class variable access from toplevel Run options: # Running tests: Finished tests in 0.067877s, 132.5928 tests/s, 132.5928 assertions/s. 9 tests, 9 assertions, 0 failures, 0 errors, 0 skips ruby -v: ruby 2.0.0p195 (2013-05-14 revision 40734) [x86_64-darwin12.4.0] /Users/pinzolo/.rbenv/versions/2.0.0-p195/bin/ruby -I"lib:test" -I"/Users/pinzolo/projects/sample_plugin/redmine-2.3.1/vendor/bundle/ruby/2.0.0/gems/rake-10.0.4/lib" "/Users/pinzolo/projects/sample_plugin/redmine-2.3.1/vendor/bundle/ruby/2.0.0/gems/rake-10.0.4/lib/rake/rake_test_loader.rb" "plugins/*/test/functional/**/*_test.rb" *** Mocha deprecation warning: Change `require 'mocha'` to `require 'mocha/setup'`. /Users/pinzolo/projects/sample_plugin/redmine-2.3.1/lib/SVG/Graph/Graph.rb:3: warning: class variable access from toplevel Run options: # Running tests: Finished tests in 0.062297s, 16.0521 tests/s, 16.0521 assertions/s. 1 tests, 1 assertions, 0 failures, 0 errors, 0 skips ruby -v: ruby 2.0.0p195 (2013-05-14 revision 40734) [x86_64-darwin12.4.0] /Users/pinzolo/.rbenv/versions/2.0.0-p195/bin/ruby -I"lib:test" -I"/Users/pinzolo/projects/sample_plugin/redmine-2.3.1/vendor/bundle/ruby/2.0.0/gems/rake-10.0.4/lib" "/Users/pinzolo/projects/sample_plugin/redmine-2.3.1/vendor/bundle/ruby/2.0.0/gems/rake-10.0.4/lib/rake/rake_test_loader.rb" "plugins/*/test/integration/**/*_test.rb"

成功したみたいなので、失敗させてみる。

# sample_model_test.rb
require File.expand_path('../../test_helper', __FILE__)

class SampleModelTest < ActiveSupport::TestCase

  # Replace this with your real tests.
  def test_truth
    #assert true
    assert false
  end
end
% bundle exec rake redmine:plugins:test:units RAILS_ENV=test
berk redmine:plugins:test:units RAILS_ENV=test (in /Users/pinzolo/projects/sample_plugin/redmine-2.3.1) *** Mocha deprecation warning: Change `require 'mocha'` to `require 'mocha/setup'`. /Users/pinzolo/.rbenv/versions/2.0.0-p195/bin/ruby -I"lib:test" -I"/Users/pinzolo/projects/sample_plugin/redmine-2.3.1/vendor/bundle/ruby/2.0.0/gems/rake-10.0.4/lib" "/Users/pinzolo/projects/sample_plugin/redmine-2.3.1/vendor/bundle/ruby/2.0.0/gems/rake-10.0.4/lib/rake/rake_test_loader.rb" "plugins/*/test/unit/**/*_test.rb" *** Mocha deprecation warning: Change `require 'mocha'` to `require 'mocha/setup'`. /Users/pinzolo/projects/sample_plugin/redmine-2.3.1/lib/SVG/Graph/Graph.rb:3: warning: class variable access from toplevel Run options: # Running tests: [1/9] SampleModelTest#test_truth = 0.00 s 1) Failure: test_truth(SampleModelTest) [/Users/pinzolo/projects/sample_plugin/redmine-2.3.1/plugins/sample_plugin/test/unit/sample_model_test.rb:8]: Failed assertion, no message given. Finished tests in 0.069086s, 130.2724 tests/s, 130.2724 assertions/s. 9 tests, 9 assertions, 1 failures, 0 errors, 0 skips ruby -v: ruby 2.0.0p195 (2013-05-14 revision 40734) [x86_64-darwin12.4.0] rake aborted! Command failed with status (1): [ruby -I"lib:test" -I"/Users/pinzolo/projects/sample_plugin/redmine-2.3.1/vendor/bundle/ruby/2.0.0/gems/rake-10.0.4/lib" "/Users/pinzolo/projects/sample_plugin/redmine-2.3.1/vendor/bundle/ruby/2.0.0/gems/rake-10.0.4/lib/rake/rake_test_loader.rb" "plugins/*/test/unit/**/*_test.rb" ] … Tasks: TOP => redmine:plugins:test:units

予定通り失敗した。
あとはテストを書いて実行していけばよさそうだ

0 件のコメント :

コメントを投稿