bsky
bsky

Reputation: 20222

Running minitest produces no output

I have a file my_test.rb with the following contents:

require 'test/unit'

class MyTest < Test::Unit::TestCase

  # Called before every test method runs. Can be used
  # to set up fixture information.
  def setup
    # Do nothing
  end

  # Called after every test method runs. Can be used to tear
  # down fixture information.

  def teardown
    # Do nothing
  end

  # Fake test
  def dummy_test
    print "Something!"
    fail
  end
end

When I run ruby my_test.rb, there is absolutely no output.

How can I run the unit tests in this file and see whether they are passing or failing?

Upvotes: 1

Views: 378

Answers (3)

matt
matt

Reputation: 79723

Test-unit will look for methods that start with “test” and use them as test methods. Your code has a method that ends with “test” but none that start with it, so it doesn’t see any tests to run.

Change the method name from dummy_test to test_dummy and you should see the output you are expecting.

Upvotes: 1

darclander
darclander

Reputation: 1811

As said before you are not calling on your function and therefore nothing will happen since ruby does not automatically execute the first / last function.

An example would be to implement this code

...
def main()
    print "Something!"
end

main()

And if you would like to call a function which calls the other functions you will do the same

Example:

def main()
    other_function1()
    other_function2()
end

main()

And the other_functions would be other functions you define and call within the main function.

Upvotes: 0

Sebasti&#225;n Palma
Sebasti&#225;n Palma

Reputation: 33420

There's nothing bad with your implementation and your actual code. But in order your dummy_test can execute what's inside its definition, it should be called first; thing you're not doing, that's why when you run your file you don't get any output.

You can create an example test, and there call your dummy_test method:

...

def test_something
  dummy_test
end

# Fake test
def dummy_test
  print "Something!"
  fail
end

Upvotes: 2

Related Questions