vendredi 3 juillet 2020

Why can't I set the order in which Unit Tests will be executed?

I'm learning about Testing reading the Rails doc, which states you can sort the order in which the tests are executed (random by default) by modifying either the application.rb or the environment files and adding:

config.active_support.test_order = :sorted

The environment files take precedence over those in config/application.rb. I've tried both but I can't make it work either way.

I have the exact same 3 tests in my model, for which I changed the names to 1, 2 and 3 and they are executed randomly each time.

  test "1" do
    article = Article.new
    assert_not article.save, "Saved the article without a title"
  end

  test "2" do
    article = Article.new
    assert_not article.save, "Saved the article without a title"
  end

  test "3" do
    article = Article.new
    assert_not article.save, "Saved the article without a title"
  end

returns 1,3,2 (test order is random every time I run rails test)

F

Failure:
ArticleTest#test_1 [/home/elianvm/code/1990eam/blog_for_testing_training/test/models/article_test.rb:18]:
Saved the article without a title


rails test test/models/article_test.rb:16

F

Failure:
ArticleTest#test_3 [/home/elianvm/code/1990eam/blog_for_testing_training/test/models/article_test.rb:28]:
Saved the article without a title


rails test test/models/article_test.rb:26

F

Failure:
ArticleTest#test_2 [/home/elianvm/code/1990eam/blog_for_testing_training/test/models/article_test.rb:23]:
Saved the article without a title


rails test test/models/article_test.rb:21

Aucun commentaire:

Enregistrer un commentaire