Oleksandr Rozumii, Toptal
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo.
Software testing is an investigation conducted to provide stakeholders with information about the quality of the product or service under test.
Test automation is the use of special software to control the execution of tests and the comparison of actual outcomes with predicted outcomes.
It's about checking that things work when needed…
…and that they do not work when it should not!
That's also named 'positive' and 'negative' testing.
defmodule Example.MatchSubscriptionTest do
@valid_attrs %{user_id: 42, msg_id: 4323, disabled: false}
test "changeset with valid attributes" do
changeset = MatchSubscription.changeset(
%MatchSubscription{}, @valid_attrs)
assert changeset.valid?
end
end
defmodule Example.EventSpec do
let :changeset, do: Event.changeset(%Event{}, attrs)
subject do: changeset.valid?
context "changeset with valid attributes" do
let :attrs, do: %{"user_id" => 42, "msg_id" => 4323,
"disabled" => false}
it "is valid" do
is_expected.to be_truthy
end
end
end
defmodule ExampleTest do
use ExUnit.Case
doctest Example
test "the truth" do
assert 1 + 1 == 2
end
end
defmodule AssertionTest do
use ExUnit.Case, async: true
test "the truth" do
assert true
end
end
setup_all do
IO.puts "Starting AssertionTest"
:ok
end
setup do
IO.puts "This is a setup callback"
on_exit fn ->
IO.puts "This is invoked once the test is done"
end
[hello: "world"]
end
assert false, "it will never be true"
refute true, "This will obviously fail"
assert_in_delta 1.1, 1.5, 0.2
flunk "This should raise an error"
defmodule SomeSpec do
use ESpec
context "Some context" do
it do: expect "abc" |> to(match ~r/b/)
end
end
defmodule SomeSpec do
use ESpec
before do: {:shared, a: 1}
let! :a, do: shared.a
let :b, do: shared.a + 1
it do: expect a |> to(eq 1)
it do: expect b |> to(eq 2)
end
describe "#prepare_event_text" do
subject do: described_module.prepare_event_text(event)
context "red team won" do
context "within 5 minutes from start"
before do: LiveMatchesStore.set_live_games_info prev_state
config.finally fn(shared) -> IO.puts shared.answer end
RSpec syntax with expect helper: expect(smth1).to eq(smth2) or is_expected.to eq(smth) when subject is defined;
expect syntax with pipe operator expect smth1 |> to(eq smth2) or is_expected |> to(eq smth) when subject is defined;
should syntax: smth1 |> should(eq smth2) or should eq smth when subject is defined.
Yeah, it's copied from README. ;)
expect collection |> to(be_empty)
expect list |> to(have_first value)
expect string |> to(have_first value)
expect map |> to(have_key value)
expect function |> to(throw_term)
defmodule SomeSpec do
use ESpec
before do: allow SomeModule |> to(accept :func)
it do: expect SomeModule.func |> to(be_nil)
it do: expect SomeModule.func(42) |> to(be_nil)
end
defmodule Factory do
def create(:company) do
...
end
def create(:city) do
...
end
end