BadMrStinger

BadMrStinger

Negative Property Test Cases

I am having a hard time coming up with negative tests. I believe it can be done with filters, but I haven’t been able to come up good working case.

Say I have this test case:

property “Positive Test” do
check all variable1 ← StreamData.integer(1..5) do
assert Enum.member?([1,2,3,4,5], variable1) == true
end
end

I would like to perform a negative test

property “Negative Test” do
check all variable1 ← !(StreamData.integer(1..5)) do
assert Enum.member?([1,2,3,4,5], variable1) == false
end
end

where !(StreamData.integer(1..5)) is any input that is the “opposite” of the valid input.

I generated a bad negative test that simply generates any term and that test has always passed, but I understand it is not mutually exclusive.

Two thoughts it would be nice if we had two types of “opposite”:

  • One that is bound to the same variable type
  • The other or any term.

In this way I could show that if a valid input exists it works, if an invalid input of the same data type is provided it fails, and all other results crash.

This would allow for the ability to potentially have a test cases that could catch any case that was expected to crash and didn’t (hardware failure?).

I would really like to take all of the properties from the positive property test and negate it, but I don’t know if this would really work for more complex properties.

All suggestion would be greatly appriciated!

Where Next?

Popular in Questions Top

New
Lily
In templates/appointment/index.html.eex: <%= for appointment <- @appointments do %> <tr> <td><%= appoi...
New
Darmani72
If I have a post route which an argument: post /my_post_route/:my_param1, MyController.my_post_handler How would get the post params ...
New
komlanvi
Hi everyone, I was playing with phoenix liveView but I run into an issue. I have a form and want to validate each input text when the te...
New
shijith.k
I am trying to start a new phoenix project with elixir 1.9, but mix phx.new does not work. It says that ** (Mix) The task "phx.new" could...
New
siddhant3030
Hi, I have to write a raw query for one of my project. But till now I have used ecto queries and don’t have much experience writing raw ...
New
WestKeys
Currently suffering from paralysis by [HTTP client] analysis. This is rather unusual in Elixirland as there tends to be consensus on the ...
New

Other popular topics Top

JeremM34
Hello, how can I check the Phoenix version ? Thanks !
New
baxterw3b
Hi guys, i’m new in the Elixir world, and i have to say, that i love it! i’m having some problem to understand anonymous functions with ...
New
sergio_101
I am VERY much an elixir newbie. I have taken one elixir course and one phoenix course on Udemy. During that course, I saw the instructor...
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
siddhant3030
Hi, I have to write a raw query for one of my project. But till now I have used ecto queries and don’t have much experience writing raw ...
New
jason.o
In the code below, if the create action is not set to accept “extra_key” as an input, it errors out with a message shown above. Is there ...
New

We're in Beta

About us Mission Statement