Ruby "test / unit" how to display messages in statements

I have statements in my ruby ​​script.

Each of these statements also has a message to describe the statement.

So, I have two questions revolving around this

  • I want the messages associated with each statement to be displayed as tests progress. Currently, the message is displayed only when something cannot

  • The whole test fails when any statement fails. How to make tests continue even if one statement fails?

Sample code that I use

assert_match("hey", "hey this is a test", "The word exists in the string") 

So the conclusion currently looks like

 ruby ruby11.rb -vv Loaded suite ruby Started test_ruby(Ruby): F Finished in 40.555587 seconds. 1) Failure: test_ruby11(Ruby11) [ruby11.rb:73]: Text box not displayed <false> is not true. 1 tests, 3 assertions, 1 failures, 0 errors 

And I want it to look like

 ruby ruby.rb -vv Loaded suite ruby Started test_ruby(Ruby): F ok 1 - First test successful ok 2 - The text is displayed ok 3 - The image is present not ok 4 - Text box not displayed ok - The picture is visible Finished in 40.555587 seconds. 1) Failure: test_ruby(Ruby) [ruby11.rb:73]: Text box not displayed <false> is not true. 1 tests, 4 assertions, 1 failures, 0 errors 

Thus, in the above display, all approval states are displayed as when the test is running. (Something like TAP in perl). I'm new to ruby, so I'm sure there is something basic that I am doing wrong.

I also tried the ruby ruby.rb -vv verbose parameter, when running the script. But that doesn't help either.

Help will be appreciated

+1
source share
2 answers

There is not much choice for TAP output. One test structure was Bacon , which was a RSpec clone with TAP output, but now it is no longer active.

If you need compatibility with continuous integration, ci_reporter gem can be used to convert test results (like from Test :: Unit and RSpec) to the JUnit XML format, which will make it work with Jenkins / Hudson, Bamboo and other CI servers that support JUnit.

But unlike RSpec, Test / Unit has a limitation in which it does not report the tests that pass. It discusses the launch of Test / Unit through the RSpec HTML formatter, which will contain the names of the skipped tests here .

Update

2015: you can look at MiniTest, which is gaining popularity now and has many formatting plugins and is otherwise very flexible / extensible.

-2
source

This is how I do it, but consider the following:

  • You have one statement per test. Each particular test must be added for a discrete piece of behavior. For example, if text may appear without an image appearing, then you have separate tests test_text_appears and test_image_appears . Having one statement per test means that when something breaks, you can see all the statements that fail, and not just the first statement in the test with many statements.
  • Ask the name of the test to describe what it should do, for example test_text_appears .
  • What error messages should I say - I'm not 100% sure that this is a good idea, so I opened a separate question: What makes a good error message for testunit or other nunit style frameworks?
0
source

Source: https://habr.com/ru/post/1385812/


All Articles