Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the difference between tests and specs?

I decided to try out MiniTest and noticed pretty quickly that it supported something called "specs". I had seen these referenced before but thought it was just an alternate test syntax associated with factories, but if that were the case then why would MiniTest need to support them both?

We only covered tests when I was taught Ruby on Rails, so I don't really know anything about specs. When I Google specs I find a lot of stuff about how to write good ones but nothing explaining what they are. What's the difference between tests and specs?

like image 941
Oblivious Sage Avatar asked May 28 '13 21:05

Oblivious Sage


People also ask

Why are tests called spec?

“Tests are specs” refers to a specific form: automated tests written in a style called “behavior driven.” Behavior-driven means that tests look like this: describe Frobber... it 'frobs'... Assume that you can write tests in a style where they describe what programs should do.

What does Spec mean in tests?

What are test specifications? Test specifications (specs) are the string used to identify tests when they're run by a test runner. Below you can see an example of the output from a failed test. You can see where the specification and assertion error is used to describe how a test failed.

What is specs in Ruby?

The specs generally serve two purposes: 1) to drive development, and 2) as a verification mechanism. These goal can sometimes be at odds. During development, the code and specs evolve together. For verification, it is desirable to have a highly stable set of specs that ideally have been audited for correctness.

Where do I put jest tests?

Where to put test files. Unit tests run against specific lines of code. So it makes sense to place them right next to that code. Integration tests run against many lines of code in many files.


2 Answers

A spec, short for specification, comes from behavior driven testing, and encourages the mindset where you are defining 'what' the software does.

Calling it a test leads to a much more general way of thinking about the code, and does not reinforce the idea that you should be testing the interface (instead of the implementation) as well.

That said, regardless of how you write them, or what you call them, the point is to have an automated way of verifying the correctness of your code, so that you can proceed with confidence.

like image 90
SciPhi Avatar answered Sep 22 '22 09:09

SciPhi


Google for tests vs. Specs. Some good reads pop up:

  • https://sites.google.com/site/unclebobconsultingllc/specs-vs-tests
  • http://betterspecs.org/

My opinion is, that specs read more 'natural' and feel more like true specifications of the functionality of the code when compared to mini-test et.al.

Rspec is a good example of a DSL, specifically written to write tests that make sense when read, even for people less technically inclined.

But in the end, use whatever makes you feel more comfortable. A test written is almost always better then no test written, because you feel uncomfortable using the testing framework

edit

After rereading your question, you seem to specifically ask about mini-test specs. It is an addition to minitests which adds rspec-like syntax to minitest. Everything above still applies.

like image 23
Sascha Kaestle Avatar answered Sep 18 '22 09:09

Sascha Kaestle