Is it possible to run a single test in MiniTest?

后端 未结 13 1613
旧时难觅i
旧时难觅i 2020-12-12 10:29

I can run all tests in a single file with:

rake test TEST=path/to/test_file.rb

However, if I want to run just one test in that file, how wo

相关标签:
13条回答
  • 2020-12-12 11:11

    I'm looking for similar functionality to:

    rspec path/to/test_file.rb -l 25

    There is a gem that does exactly that: minitest-line.

    gem install minitest-line
    ruby test/my_file -l 5
    

    from https://github.com/judofyr/minitest-line#minitest-line

    0 讨论(0)
  • 2020-12-12 11:13

    You can pass --name to run a test by its name or a number within its name:

    -n, --name PATTERN               Filter run on /regexp/ or string.
    

    e.g.:

    $ ruby spec/stories/foo_spec.rb --name 3
    
    FAIL (0:00:00.022) test_0003_has foo
    Expected: "foo"
    Actual: nil
    

    This flag is documented in Minitest’s README.

    0 讨论(0)
  • 2020-12-12 11:13

    No gem required: ruby -Itest test/lib/test.rb --name /some_test/

    Source: http://blog.arvidandersson.se/2012/03/28/minimalicous-testing-in-ruby-1-9

    0 讨论(0)
  • 2020-12-12 11:15

    If you are using Turn gem with minitest, just make sure to use Turn.config.pattern option since Turn Minitest runner doesn't respect --name option in ARGs.

    0 讨论(0)
  • 2020-12-12 11:18

    You can use this to run a single file:

    rake test TEST=test/path/to/file.rb
    

    I also used

    ruby -I"lib:test" test/path/to/file.rb
    

    for better display.

    0 讨论(0)
  • 2020-12-12 11:20

    This is one of the things that bother me about the string name definition in tests.

    When you have:

    def test_my_test
    end
    

    you always know how your test is named so you can execute it like this:

    ruby my_test -n test_my_test
    

    But when you have something like:

    it "my test" do
    end
    

    you are never sure how this test is really named internally so you can not use the -n option just directly.

    To know how this test is named internally you only have an option: execute the whole file to try to figure out looking in the logs.

    My workaround is (temporally) add something to the test name very unique like:

    it "my test xxx" do
    end
    

    and then use the RegEx version of the '-n' parameter like:

    ruby my_test.rb -n /xxx/
    
    0 讨论(0)
提交回复
热议问题