Is it possible to mark tests as incomplete or skipped in ExUnit?

Title says all!

Is it possible to manually mark tests as incomplete or skipped in ExUnit, in the middle of a test case?

1 Like

Hmmm but I’m looking to skip something on the fly, this requires a definition beforehand.

I’m talking about skipping a test if a condition is met inside.

Context: I’m building something that does snapshot tests like Jest (JS) has, and want to mark a test incomplete the first run.

I do not know Jest, and I think others don’t do as well.

Can you please elaborate how this snapshot testing works from a users perspective?

Snapshot testing takes a string which you pass to an assertion function, and looks for an existing “snapshot” file. If there’s no snapshot file, a new one is stored. If there is an existing snapshot file from a previous run, the string you’ve asserted on is compared to the snapshot for regressions. This is also known as characterization testing.

The Jest docs have a whole article on it:

So, I’d like to mark the tests as incomplete on the first one, since nothing’s really tested yet then.

Maybe you can use a custom test macro to be able to mark the test with the status you want, like stream_data does here:

I prefer property testing too, but yeah it would be easy to write something like assert_prior <expr> or so that talks via DETS to a snapshot file.

I was searching for some information regarding ExUnit and snapshot tests and I have encountered this thread. In case anyone is interested I have created my own package for snapshot tests and it is available here: Extensive documentation, tests etc. are coming, but would like to get your feedback on it :wink:

P.S. It is my second ever project in Elixir and first ever package, so I’d really like to hear your thoughts on it :blush:

You can also mark a test as skipped inside the setup block.

setup context do
  if check_for_something do
    {:ok, skip: true}

For those landing from Google, you can skip any test by annotating it with a :skip tag:

@tag :skip
test "not implemented yet"

Seems it does not work anymore, just gave it a try. Is there a new way of ignoring tests dynamically on the setup?

1 Like