Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting up Test Suite in Ruby

I am trying to setup a test suite in Ruby to automate the Testing of a WebUI (using Watir)

The individual tests are fine and all run correctly, but I am having problems with the suite.

Eg if one of my tests is (where BaseTestClass extends Test::Unit::TestCase)

class Test3_1_3_1_2 < BaseTestClass
  def testHeightOfMainPanel
    assert(false, 'Not implemented')
  end
end

In my RunAllTests script I am trying to do the following

require 'test/unit'

Test::Unit.at_start do
  #Lets create our own user for these tests
  createCCUser(User, Password)
end

Test::Unit.at_exit do
  #Delete our own user
  deleteUser(User)
end


Dir["./**/Test*.rb"].each{|s|
  puts s.to_s
  load s
}

So basically what I want to do is create a new user at the start of the tests, run the tests and then delete the user. This is necessary because the system is a single sign on (kinda) and if we used the same user for everyone, there is no guarantee that the tests will execute properly (ie someone else could run the test at the same time and then the first user would be kicked out)

The errors I am getting are: undefined method at_start' and private methodat_exit' called

I know I am doing something wrong, but being very new to Ruby it is hard to see where. Basically what I need is a way to perform some setup run all the tests that can be found, and then do a cleanup. Each test has its own separate setup and teardown methods

I should also add, I have tried many variations of the same above, eg

require 'test/unit'

class Temp < Test::Unit::TestCase
  Test::Unit.at_exit do
    #Delete our own user
    deleteUser(User)
  end


  Test::Unit.at_start do
    #Lets create our own user for these tests
    createCCUser(User, Password)
  end

  Dir["./**/Test*.rb"].each { |s|
    puts s.to_s
    load s
  }
end

And I still don't get it. Any help would be appreciated

like image 297
Dace Avatar asked Nov 08 '12 14:11

Dace


People also ask

How do I run a test case in Ruby?

We can run all of our tests at once by using the bin/rails test command. Or we can run a single test file by passing the bin/rails test command the filename containing the test cases. This will run all test methods from the test case.

What is the testing framework for Ruby?

test-unit (Test::Unit) is unit testing framework for Ruby, based on xUnit principles. These were originally designed by Kent Beck, creator of extreme programming software development methodology, for Smalltalk's SUnit. It allows writing tests, checking results and automated testing in Ruby.

How do you test a method in Ruby?

Most methods can be tested by saying, “When I pass in argument X, I expect return value Y.” This one isn't so straightforward though. This is more like “When the user sees output X and then enters value V, expect subsequent output O.” Instead of accepting arguments, this method gets its value from user input.


1 Answers

I think the problem is, assuming you are using Ruby 1.9.3, is the confusion regarding which gem is being required by require 'test/unit'.

In Ruby 1.9.3, require 'test/unit' will require the "Minitest" gem. The methods you want to use do not exist in this gem.

The at_start and at_exit methods exist in the the test-unit gem.

Assuming you have both the Minitest gem (installed by default in Ruby 1.9) and Test-Unit gem (manually installed using gem install test-unit), you need to specifically state you want the test-unit gem.

Before requiring test/unit, specify the usage of the test-unit gem:

gem 'test-unit'
require 'test/unit'
like image 86
Justin Ko Avatar answered Oct 02 '22 21:10

Justin Ko