victorolinasc

victorolinasc

Hello people! Just wanted to bring a discussion to the community that happened on my team.

When it comes to testing, naming the tests is itself an art. There are several approaches and all of them and none of them are right/wrong. I’ve seen several patterns through the community and some others on my team because of the different backgrounds each have on the subject. I’d like to know your opinions about it.

Different styles

Here is some styles I’ve seen:

  • The AAA approach (arrange - act - assert): gives names like test "given a proper user when it authenticates it receives a proper session"
  • The “it does some result” approach: test "it authenticates properly"
  • The “it capabilities” approach: test "it can authenticate an active user"
  • The “result verb” approach: test "succeeds authentication with an active user"
  • The “action” approach: test "authenticates an active user"

So on …

Describe and trace option

What gives me some anxiety is the way the sentence ends up when we use “describe” and the “–trace” option.

The pattern ExUnit uses is: "test #{describe_text} #{test_text}". So the end result could be something like:

“test some_function/1 it authenticates properly”

This is strange to read. But to make it more plausible we would have to add a strange clause to desribce like describe "that some_function/1" do ... end. So on the report it would be:

“test that some_function/1 succeeds with an active user”

We could use a different approach and use the action directly:

“test some_function/1 can authenticate an active user”

What are your thoughts on good unit testing naming? Sorry for English mistakes. Altough I am picking on the grammar here, English is not my mother’s tongue.

Most Liked

dimitarvp

dimitarvp

describe "MyModule.my_function/1" do

  test "authenticates successfully with valid parameters" do
  end

  test "fails authentication with invalid parameters" do
  end

end

Last Post!

dwahyudi

dwahyudi

Test user can authenticate normally
Test authentication via google account
Test registration via google account
Test user cannot authenticate when wrong username / password
Test user cannot register with invalid mail format
Test user can add item to cart
Test user cannot add out of stock item to cart
Test calculation of order discount
Test completed order not to be editable
Test driver can pickup customer
Test driver can complete customer’s order
Test blocked user cannot comment on user’s post
Test unregistered visitor can see products

And so on.. I kinda think that test is equal to specify in rspec.
it and specify in rspec is just the same, but it is usually followed by verbs.

it should
it must
it allows
it forbids

Where Next? Top

Trending in Discussions Top

AstonJ
As the title says, please share what you’ve been up to with Elixir. Whether that’s been learning it, looking into it, making stuff with i...
2977 92995 915
New
caslu
I want to open this thread for you all to discuss and help those who really like Ash but are still hesitant to use it in a real project. ...
New
mudasobwa
I am happy to introduce the very α version of the new programming language compiled to BEAM. Welcome Cure. It has literally three kille...
New
Herve37
We’re evaluating API mocking tools for OpenAPI-based projects and would love to hear what other teams are using. We’re particularly inte...
New
GES233
I’m posting this in response to Jose’s recent tweet (Cr. link) : People are sleeping on Elixir for a coding harness: Hot-code swappi...
New
_mfierro
Hello, I wrote Stop My Hand, a Scattergories-like web application using Phoenix/LiveView as my learning project for Elixir (after readin...
New
nseaSeb
AcmeScript — Writing JS hooks as if I were still using Elixir I’ve been having fun building a little something over the last few days: Ac...
New

Other Trending Topics Top

garrison
Hobbes is a low-level distributed database for the Elixir programming language. Hobbes provides a simple, safe, and scalable storage lay...
New
mcass19
ExRatatui lets you cook up rich terminal UIs in Elixir, powered by Rust’s ratatui via Rustler NIFs. Build interactive terminal applicatio...
New
Damirados
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge & Solve. They are GUI (Emerge) and State management (S...
New
netoum
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New
wintermeyer
There are three potential reasons for members of this forum to have a look at https://vutuv.de You are tired or annoyed of LinkedIn. Yo...
New
webofbits
Aludel - LLM Evaluation Workbench Aludel is an embeddable Phoenix LiveView dashboard for evaluating and comparing LLM prompts across mult...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews