unit test in ruby not printing results to console - ruby

I'm trying to set up a testing environment in ruby using rake. It seems like the code I have gets reached by rake but it doesn't return any test results. I'm hoping I'm missing something simple and you could lend me a hand.
rakefile
require 'rake'
require 'rake/testtask'
Rake::TestTask.new do |t|
t.libs = ["lib"]
t.warning = true
t.verbose = true
t.test_files = ['test/numbersTest_test.rb']
end
task default:[:test]
numbersTest_test.rb
require "test/unit"
class TestMyApplication < Test::Unit::TestCase
def dummyCase
assert(false, "dummy case failed")
end
end
Result when I run "rake"
C:\Users\Daniel\Classes\assign1\PerfectNumbersRuby
λ rake
C:/Ruby21-x64/bin/ruby.exe -w -I"lib" -I"C:/Ruby21-x64/lib/ruby/gems/2.1.0/gems/rake-10.4.2/lib" "C:/Ruby21-x64/lib/ruby/gems/2.1.0/gems/rake-10.4.2/lib/rake/rake_test_loader.rb" "test/numbersTest_test.rb"
test

There are no testcases in your code. Testcases are methods whose name starts with test_.

Related

Rake::TestTask is not working inside another task

We have developed few test cases using mini-test / ruby
Now we are trying to run it using rake files.
its working fine if we are running below code.
require 'rake'
require 'rake/testtask'
Rake::TestTask.new do |t|
t.test_files = FileList['../Home/*TC1.rb']
t.verbose = true
end
But we are putting the above code in separate task then id does not run the test
task :myCustom_task do
Rake::TestTask.new do |t|
t.test_files = FileList['../Home/*TC1.rb']
t.verbose = true
end
end
Then we run it by below command
rake myCustom_task
and it does not run the test.Also it does not show any error while running with --trace option.
What is missing in this approach ?

Rake not running any tests with minitest

I have a file containing a class of multiple tests (using minitest). I have require 'minitest/autorun' at the top of the file and all tests run correctly when I call the file directly (ruby my_tests.rb).
So far, so good. However, now I'm trying to run my tests via rake.
require "rake/testtask"
task :default => [:test]
Rake::TestTask.new do |t|
t.libs << Dir.pwd + "/lib/examples"
t.test_files = FileList['test/test*.rb']
end
Calling rake shows test/my_test.rb getting called but no tests within the class get run (0 tests, 0 assertions, etc.). I do get these warnings:
...gems/minitest-5.8.0/lib/minitest/assertions.rb:17: warning: already initialized constant MiniTest::Assertions::UNDEFINED
...ruby/2.1.0/lib/ruby/2.1.0/minitest/unit.rb:80: warning: previous definition of UNDEFINED was here
How can I run my tests within rake successfully? I am not using rails.
EDIT: Here is the top of my test file:
require 'minitest/spec'
require 'minitest/autorun'
require 'minitest/reporters'
reporter_options = { color: true }
Minitest::Reporters.use![Minitest::Reporters::DefaultReporter.new(reporter_options)]
class Test_PowerSpecInputs < Minitest::Test
def setup
#mc = TestClass.new()
end
def test_does_lib_have_constant
# my test code
end
end
Try changing your Rakefile to this.
require "bundler/gem_tasks"
require "rake/testtask"
Rake::TestTask.new(:test) do |t|
t.libs << "test"
t.libs << "lib"
t.test_files = FileList['test/**/*_test.rb']
end
task :default => :test
jphager2 got me thinking about tool versions and it turned out that my version of rake was fairly old. Updating to 11.x did the trick.

ActiveSupport TestCase not running in Sinatra

I'm setting up a new Sinatra app and am having issues getting my tests to run via a rake task. When I run rake:test, the task runs, shows me which files it will be running, but nothing happens. I know it's loading the class because it has failed due to syntax errors, but I never see my tests running. What am I missing? Below is my configuration and example test:
rakefile.rb
require "rake/testtask"
require "sinatra/activerecord/rake"
require "./app"
task :default => :test
TEST_FILES = FileList["test/**/test*.rb"]
desc "Run all of the tests for redFish"
Rake::TestTask.new do |t|
t.libs << "test"
t.test_files = TEST_FILES
t.verbose = true
end
task :default => "test"
test/test_helper.rb
ENV["RACK_ENV"] = "test"
require "rack/test"
require "awesome_print"
require "active_support"
require "active_support/core_ext"
/test/unit/test_organization.rb
require File.expand_path '../../test_helper.rb',__FILE__
class TestOrganization < ActiveSupport::TestCase
def setup
puts "setup for tests"
end
test "validates_required_fields" do
puts "RUNNING TESTS"
assert true
refute false
end
end
When I run rake:test, I can see that test_helper and test_organization.rb are being found by the TestTask, but I don't see any tests pass/fail.
Am I missing something obvious?
Looks like the issue was caused by not requiring minitest/autorun in my test helper. I added that line, and the tests ran fine.

Rake TestTask won't run Unit Tests

my rake TestTask looks like this
Rake::TestTask.new(:tasks) do |t|
t.libs << "test"
t.test_files = FileList['tasks/tasks*.rb']
t.verbose = true
end
My unit test named tasks01.rb looks like this
require_relative '../../class_based_page_objects/tasks/add_task'
require_relative '../../class_based_page_objects/tasks/tasks_grid_view'
require_relative '../../helpers/ssh_test_session'
require_relative '../../class_based_page_objects/login'
require "test-unit"
gem "test-unit"
require "selenium-webdriver"
puts "Will you print this?"
class Task01Test < Test::Unit::TestCase
def setup
#test Setup goes here
puts "Setup"
end
def test_assign_to_not_real_user
# Test goes here
puts "Test"
end
end
When I
rake tasks
I get
"Will you print this?"
What am I missing?
You just need a description line in your Rakefile code, like so:
desc "A description here without a period"
Rake::TestTask.new(:tasks) do |t|
t.libs << "test"
t.test_files = FileList['tasks/tasks*.rb']
t.verbose = true
end

What am I doing wrong with my rakefile?

This is the only thing in my rakefile.
Rake::TestTask.new do |t|
t.libs << "test"
t.test_files = FileList['test/test*.rb']
t.verbose = true
end
When I run rake the output I get is
uninitialized constant Rake::TestTask
What am I doing wrong? I want my rake file to run all unit tests that I specify. Any input would be helpful.
Thanks
What happens if you require 'rake/testtask' at the top of the file?

Resources