How to output names of ruby unit tests
Run unit test with verbose option.
test.rb -v v
or
test.rb --verbose=verbose
Output:
Loaded suite C:/test
Started
test_something(TC_MyTest): .
Finished in 0.0 seconds.
1 tests, 1 assertions, 0 failures, 0 errors
Ruby Test::Unit's current test method name
I got it!
The test name gets passed up the inheritance chain, so I just needed to capture it and save it locally for my reference.
def initialize(name = nil)
@test_name = name
super(name) unless name.nil?
end
How to get name of the test program along with dots while running ruby test
you should have a look at github.com/TwP/turn -- it produces colorized output, outputs PASS/FAIL per test method and, most importantly, it shows you the relevant failure/error right after it has occured, not "after all the dots".
The Readme at Github has all the relevant info.
Outputting (puts, print) in Rails Unit Tests
You can use the rails logger to see your output:
Rails::logger.debug "Interesting stuff"
Run tail -f log/test.log
on the command line (from the project's root in a separate Terminal tab or window) to see the results.
Print a List of All Tests in a Rails App
I have found a roundabout solution: the test_benchmarker plugin. You run your tests with an extra environment variable like so:
rake test BENCHMARK_TESTS=true
You're best off piping the output to a file, because it will be long. But it will give you a list of all the test classes and tests themselves, for both unit and functional. Obviously it gives you the benchmarking results too, which is a bonus.
Is there anything better? I guess this is pretty close, and the extra effort is so little, why NOT get the benchmark results too? RSpec has this feature built in, but maybe it'd be fun to write a version for Test::Unit.
Create an rspec test to return a name
well you seem to need a game created_by
field which you should add, you then need to set it when you create the game and then return it when you start the game, something like this:
class Game
attr_accessor :created_by
attr_reader :process, :output
attr_writer :process, :output
def initialize(output, created_by)
@output = output
@created_by = created_by
puts "[#{@output}]"
end
def start
@output.puts 'Welcome to the Impossible Machine!'
@output.puts 'Starting game...'
@output.puts @created_by
# code to return student's name here
end
end
Creating a test report using Ruby unit test
One alternative - simple - is to work with the output provided using command line string manipulation tools (sed/awk/..) and generate the required output format.
A more involved alternative would be to dig into the test-unit internals and create your own test-runner which gives the required output. The ./lib/test/unit/ui/console/testrunner.rb file would be a good place to start.
Check out https://stackoverflow.com/a/10558600/429758 for an example of how to write a customized test runner.
Ruby testing: printing inside a test case
Ruby asserts can output messages to test runner console:
test "thing to happen" do
do_stuff
assert_equal "foo", @variable, "@variable is #{@variable} when: things to happen"
p @varible
end
Rails test hanging - how can I print the test name before execution?
If you run test using rake it will work:
rake test:units TESTOPTS="-v"
Related Topics
How to Organize Minitest/Unit Tests
Ruby on Rails: How to Check If a File Is an Image
Strictly Convert String to Integer (Or Nil)
Heroku: How to Push Seeds.Rb to Existing Rails App
Rails 3: Call Functions Inside Controllers
Connecting Using Https to a Server with a Certificate Signed by a Ca I Created
Setting Up Facets in Elasticsearch with Searchkick Gem in Rails 4.1
How to Test for a Redirect with Rspec and Capybara
Rails Console Default Environment
Converting Date Object to Timewithzone
Ruby: How to Group a Ruby Array
How to Install 'Cocoapods' Gem from Rubygems.Org (Bad Response Backend Read Error)
Using Gets() Gives "No Such File or Directory" Error When I Pass Arguments to My Script
Resetting a Singleton Instance in Ruby
How to Look Up Elevation Data by Lat/Lng