Skip to content

Instantly share code, notes, and snippets.

@lazyatom
Last active December 11, 2015 21:09
Show Gist options
  • Save lazyatom/4660376 to your computer and use it in GitHub Desktop.
Save lazyatom/4660376 to your computer and use it in GitHub Desktop.
There's no way to definitively run a single test using MiniTest as it currently stands.
require "minitest/unit"
require "minitest/autorun"
class MyTest < MiniTest::Unit::TestCase
def test_something
assert true
end
end
class AnotherTest < MiniTest::Unit::TestCase
def test_something
flunk
end
end

(Here's my proposed fix for this)

First, print out the test names:

$ ruby minitest.rb -v                 
Run options: -v --seed 58440

# Running tests:

AnotherTest#test_something = 0.00 s = F
MyTest#test_something = 0.00 s = .


Finished tests in 0.000664s, 3012.0482 tests/s, 3012.0482 assertions/s.

  1) Failure:
test_something(AnotherTest) [minitest.rb:12]:
Epic Fail!

2 tests, 2 assertions, 1 failures, 0 errors, 0 skips

Next, try running a specific test:

$ ruby minitest.rb -n "AnotherTest#test_something"
Run options: -n AnotherTest#test_something --seed 8523

# Running tests:



Finished tests in 0.000480s, 0.0000 tests/s, 0.0000 assertions/s.

0 tests, 0 assertions, 0 failures, 0 errors, 0 skips

What? Nothing ran? Indeed. It's because as far as MiniTest cares, the suite name isn't part of the test name. So you can only use parts of the test name in your filters:

However, there's no guarantee (nor should there be) that test names will be unique across suites:

$ ruby minitest.rb -n "test_something"            
Run options: -n test_something --seed 30485

# Running tests:

F.

Finished tests in 0.000645s, 3100.7752 tests/s, 3100.7752 assertions/s.

  1) Failure:
test_something(AnotherTest) [minitest.rb:12]:
Epic Fail!

2 tests, 2 assertions, 1 failures, 0 errors, 0 skips

So when we try to target a single test, both tests run. Bums.

(Here's my proposed fix for this).

@lazyatom
Copy link
Author

I've implemented my attempt a fix here: lazyatom/minitest@2b12aaa

Any thoughts?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment