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.

Showing Posts 1 to 2

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
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

— All posts loaded —

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 94592 917
New
cblavier
Hey there, It’s been more than a year since we started using LiveView as our main UI library and building a whole library of UI componen...
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
heathen
Quite interesting article Google brought me. Didn’t find any mentions about it here. What do you think in general? Would you use togethe...
New
marciol
It would be helpful to have a list of companies worldwide that hire engineers without prior experience in Elixir. Often, it can be quite ...
New
durvia
Anyone running long-lived stateful processes on BEAM? We’re building an AI agent runtime and would love to compare notes. We’re a small ...
New

Other Trending Topics Top

marciok
Hi there! We created Gust: A task orchestrator inspired by Airflow. For those who have never heard about Aiflow, it’s a Python-based wor...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Dmk
Xamal is a deployment tool for Elixir apps that deploys native releases to bare metal servers over SSH. It’s a port of GitHub - basecamp/...
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
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