RicoTrevisan

RicoTrevisan

How do you test? What do you test?

Asking for a friend. :sweat_smile:

Seriously, my “technical journey” (air-quotes) has been: VLOOKUP on Excel → no-code (Bubble.io) → snorted some JavaScript → and now I’m mainlining Elixir & Phoenix on everything.

I’ve heard about given-when-then, exploratory testing, and I’ve seen people go through a test suite. I think I kinda understand as an end user testing, but I’m not sure I get it when it comes to the code side of it. I tried to get ChatGPT and Claude to ELI5 but I always have this sneaking suspicion that might not be the best instructors.

So, imagine you had a young brother who knows some ideas of programming, but he’s missing the foundation: where should he start? Which concepts, thought-technologies, frameworks should he start with? Are there books / videos / channels you recommend?

Showing Posts 1 to 10

Bodhert

Bodhert

Hello! there are really tons of resources about testing with elixir, from courses, books, post, you name it. @germsvel, is the guy that you can check out, he had put a lot of effort on this topic, I will name a few testing live view is a paid resource, the former employer bought it and it has pretty good material, or a free one testing with phoenix, also has a talk: Using DDD concepts to create better Phoenix Contexts, anyway there are a lot of resources. I just name a few that In my experience bring a lot of value

dimitarvp

dimitarvp

I think you might be over-analyzing it. IMO just start and then ask yourself: “Which parts I want to make sure keep working after I change code in places X and Y?”.

This is honestly the best way to gauge that I ever found. There have been metrics tons of material written about religiously testing everything or testing the bare minimum. Truth is always in the middle as I think most mature people know – so use the above benchmark.

al2o3cr

al2o3cr

There’s no end of articles telling you the “right way” to test, but IMO you’ll be better-served by writing ANY tests and learning from there.

The simplest possible ExUnit test could look something like this:

defmodule AssertionTest do
  use ExUnit.Case

  test "the truth" do
    result = 2 + 2

    assert result == 4
  end
end

There are plenty of tools in the ExUnit toolbox to make writing related tests more efficient (setup blocks, tags, etc) but none of them are required to get started.

If you aren’t writing tests currently, then presumably you are running your code somehow to verify that it works the way you intend - for instance, by poking around in iex.

One approach to start writing tests is to literally just PASTE that poking around into a test block; that way you can run them over and over again without having to manually set things up or worry about missing steps.

At the beginning, copy-paste with wild abandon - you’ll eventually want to reduce duplication, but it will be much easier to spot “what’s common” vs “what’s unique” when there are more examples to review.

sodapopcan

sodapopcan

This realization is what got me into testing and what sold me on “test first” (which I am not religious about). Afterwards I have a written test that I can choose to keep or not. I still poke around in the REPL to start, though.

Yep! It’s just one of those things that requires practice where you can sniff out what is necessary to test. I use tests to help guide design but ultimately I only really care about regression/acceptance tests.

A good metric to think about is how you feel about refactoring at any given moment. If the answer is “confident” then you probably have the “right” tests. If the answer is “not at all” then you don’t have enough tests. If the answer is “I’m afraid to because of all the tests I’m going to have to fix,” then you have too many tests/too fined-grained tests. This is, of course, isn’t perfect in of itself. Unfortunately it really is one of those complex topics you just have to start doing to get a feel for because ya, you’re going to get a lot of conflicting advice.

EDIT: Quoting @al2o3cr but generally responding to @RicoTrevisan.

dimitarvp

dimitarvp

As you yourself said below, regression & acceptance tests are super important. And as I said above, I got “sold” on testing when I realized that I liked something that worked and didn’t want it to stop working so I… discovered testing back then, long long time ago. :smiley:

So a repeated message to OP: don’t get religious about testing, just test what you think is important to keep working in your project.

sodapopcan

sodapopcan

There’s a fairly popular-with-the-kids YouTuber who tells people not to write tests at all so :person_shrugging:

dimitarvp

dimitarvp

Well, who are we to stop them. Maybe that’s a shortcut to making more money with software? These days I am more result-oriented.

sodapopcan

sodapopcan

Yep, that’s more or less what I’m getting at. I wouldn’t want to work that way, but lots of people have very different ways of working and somehow still produce profitable software. There’s so much context around all of this stuff but people don’t like hearing that and just want to be told The One True Way.

dimitarvp

dimitarvp

Yep, agreed, we should throw away any religion-like thinking from our profession. The only hill I am willing to die on these days is – strong static typing. I’ve witnessed the bug reduction of that first-hand, a number of times, and I am now tired of replicating the work that really smart and good compilers do, with my own hands, in dynamic languages like Elixir.

But I can’t deny Elixir’s REPL and very strong poke-ability (if that’s a word) are still keeping me hooked to it. And being able to just get inside a k8s pod and connect to the real prod DB and fix a problem with Elixir code (and not with Postgres SQL statements inside psql) is something I am still not willing to give up – though I haven’t given a fair chance to the alternatives either… :innocent:

But it’s still a coin toss. F.ex. we like fiddling in iex and prototype stuff and I cringed not having that in Rust… but in Rust you are thus encouraged to write your stuff in a modular and decoupled manner and have tests for it almost right away, and this flow becomes your “iex”. Because if you don’t do it like that then you can code for a full week without being able to see if your idea works. But if you write in certain ways you can have almost the same iteration speed as with Elixir.

Both approaches netted me very good software so again, in the end it’s just preference. I at least still haven’t found OneTrueWay™ to do things. I lean on the side of messing around in the REPL but I’ve seen several other approaches and they worked just as good as well.

D4no0

D4no0

That’s funny because I come from startup environments where tests are not written usually because “we don’t have time”, which results in at least 3x time spent afterwards on debugging stuff, stuff that is as stupid as passing parameters in wrong order for a function.

All software should be written with tests, otherwise development velocity is not possible, that is true for 100% of untested projects I worked on.

Where Next? Top

Trending in Questions Top

RSP87
I’m working on a project that simulates the bumbl example in the programming phoenix book. It acts almost like an email client. We have a...
New
kszambelanczyk
Hello! Could someone please give me a help/sample code, how to delete a file from s3 using waffle/waffle_ecto from Phoenix app. I creat...
New
RemyXRenard
I’m seeing that a list inside a Kino.DataTable will be interpreted as a charlist, even if the Kino.configure() is set to charlists: :as_l...
New
velrest
So my question is quite simple and i have found no conclusive answer on forum, google or AI. Should we use :erlang.float for Integer to ...
New
samoloth
Hi, I’ve just set up an application with ash_authentication. There is only magic link strategy for now, so there is no confirmation add o...
New
FlyingNoodle
If a change or preparation module uses Ash.Changeset.get_argument/2 or Ash.Query.get_argument/2 (or any of the other get_argument functio...
New
psy-q
I’m trying to set up Emacs with elixir-ls via lsp-mode and credo via Flycheck. This should mostly be preconfigured as Flycheck picks up c...
New

Other Trending Topics Top

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
garrison
Hobbes is a low-level distributed database for the Elixir programming language. Hobbes provides a simple, safe, and scalable storage lay...
New
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

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews