mmport80

mmport80

Property Testing a CRUD API

I am sketching out how to test a CRUD API.

My idea is to create a simplified model / FSM, generate different states and test for properties based on the model.

E.g. assuming everything’s successful,

  1. GET /users
  2. POST /create/id/9
  3. DELETE /delete/id/9
  4. GET /users

users from 1. and 4. should be the same

Then do the a similar test when

  1. GET /users
  2. POST /create/id/8
  3. GET /users

3.'s users should have one more entry etc.

or when

  1. GET /users
  2. POST /create/id/11
  3. DELETE /delete/id/54 //:error
  4. GET /users

Again 4’s users should have one more entry.

basically, setting properties for as many cases I can, and then testing with random test-cases.

Problem is, I cannot find much material online, I am sure it is pretty standard esp. as CRUD APIs are pretty standard… (?)

Most Liked

david_ex

david_ex

From What is a Property (online version of the book, prior to having been edited):

Finally, there’s a rare but great type of modeling that may be available, called “the oracle”. An oracle is a reference implementation, possibly coming from a different language or software package, and can therefore act as a pre-written model. The only thing required of the programmer to test the system is to compare their implementation with the oracle and ensure the same results are given.

idi527

idi527

Problem is, I cannot find much material online

I think https://propertesting.com/ is pretty good.

dimitarvp

dimitarvp

For a server-side rendered CRUD website I’d concentrate on making StreamData generators of controller parameters – omit mandatory fields, send fields with invalid data in them, try and update or delete non-existing IDs, send fields that your app isn’t at all expecting. StreamData can be really alien at start but when you experiment with it for a weekend you can do some seriously powerful data generators with it!

mmport80

mmport80

I ended up following the book’s recommendations (https://propertesting.com/) e.g. create an ‘oracle’ state machine.

Basically, you create random states by interacting with your API and keep a record in your oracle.

You compare both oracle state and results from your API, and make sure they are always the same.

You’d be surprised the bugs you catch… I really need to try and bundle this into a library, am sure you could test lots of apps pretty easily with one library…

Where Next?

Popular in Questions Top

JDanielMartinez
Hi! May someone helps me, please! I have two apps into an umbrella project: the first one is Database, which manages queries, and the se...
New
dotdotdotPaul
Okay, I'm having a heck of a time trying to figure out how to best handle the validation of belongs_to associations in Ecto. I'm sure I'...
New
bsollish-terakeet
Credo is smart enough to check for (something like) this: assert length(the_list) == 0 with this response: Checking if an enum is empt...
New
logicmason
Hi there, I'm working through my first release with elixir/phoenix. I've built a release with distillery and found that it crashes when I...
New
vertexbuffer
Hello, can anybody help here..? I have a list of players and I what to delete an element, but every for loop the list is reverting to ori...
New
vac
Hi, I'm quite new in Elixir and I'm trying to format a string to a PEM format. I have the certificate value like MIIDBTCCAe2...... and ...
New
chensan
I have a User schema with a :from_id field set to type :string: defmodule TweetBot.Repo.Migrations.CreateUsers do use Ecto.Migration ...
New
chewm
Hi guys, nice to meet you to the whole forum, I’m new here, I’m trying to configure visual studio code for elixir, right now the intellis...
New
chrisalley
ExUnit now has describe blocks which is a welcome addition coming from RSpec. In the docs, it states that nested hierarchies of describe ...
New
Patoshizzle
After calling mix ecto.create I get this error: 17:00:32.162 [error] GenServer #PID<0.412.0> terminating ** (Postgrex.Error) FATAL...
New

Other popular topics Top

shahryarjb
Hello, I get Persian date from my client and convert it to normal calendar like this: def jalali_string_to_miladi_english_number(persi...
New
senggen
Erlang/OTP 25 [erts-13.2.2] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] 15:22:35.803 [error] gen_event {lager_file_backend...
New
JorisKok
I have a server on AWS, and was running a load test using artillery. When looking at the Phoenix dashboard I see the Ports going to 100% ...
New
ycv005
I have followed this StackOverflow post to install the specific version of Erlang. And When I am running mix ecto.setup then getting fol...
New
SoCreat
i’m a new one to elixir which editor can i use vs code? or atom? Thanks! :smiley:
New
script
If I have a string “1000 cfu/ml” . I want to remove the characters and / and space . So the string is like this "1000" What is the ...
New
vac
Hi, I'm quite new in Elixir and I'm trying to format a string to a PEM format. I have the certificate value like MIIDBTCCAe2...... and ...
New
myronmarston
The Elixir Typespec docs show the following syntax for keyword lists in typespecs: # ... | [key: type] # keyword lis...
New
mcarvalho
What is the difference between System.get_env and Application.get_env? For example, what are best practices to use one versus another.
New
ashish173
I am using Ecto timestamps with postgres, I can see the timestamps() use the :naive_dateime but for my use case I wanted to store the ti...
New

We're in Beta

About us Mission Statement