exkorpion v0.0.2 Release Notes

Release Date: 2016-09-13 // over 6 years ago
  • ๐Ÿ— Build Status
    ๐Ÿ“ฆ Hex version
    Hex downloads


    โœ… An Elixir framework to do testing in a BDD way


    ๐Ÿ“ฆ Library is available in Hex, the package can be installed as:

    โž• Add exkorpion to your list of dependencies in mix.exs:

    def deps do [{:exkorpion, "~\> 0.0.2"}]end

    In case of you don't have a elixir environment ready to code, please have a look at the below links:

    Exkorpion goals

    • It wraps ExUnit and enhances their features providing developers with a BDD syntax.
    • โœ… It helps us to write tests wasy-to-read.
    • It is completely compatible with ExUnit.
    • โœ… It force us to structure our tests in steps (given-when-then)
    • โœ… It is based on a functional syntax, organization our tests steps by anonymous functions.
    • It is not coupled to any other framework.

    Getting started

    Exkorpion syntax

    As was mentioned on the above Exkorpion is mainly oriented to a bdd syntax:

    scenario : A scenario groups multiple cases that test a functionality works as expected. By using scenario we achieve the below:

    • ๐Ÿ‘ Better documentation for other developers.
    • โœ… Test are better organized and structured
    • Working under an agile methodology we can match scenarios to acceptance criteria

    it : Exkorpion provide with a reserved word It to represent any of the cases inside a scenario.

     scenario "testing sum operation works as expected" do it "sum positive numbers works as expected" doend it "sum negative numbers and it should work as expected" doendend

    with/given/when/then : These word are the ones that provide us with s BDD syntax. Actually even when we write some unit tests we should thinkg about them.

    Given: It defines the input data for performing the tests. (It's an optional step, it could be not neccessary sometimes)

    When: It performs the action to be tested.

    Then: It ensures the result in the preoviuos step are the expected.

     it "Ensures that get tracks service returns always 2 elements" do %{ when: fn \_ -\> %{result: build\_conn() |\> get("/tracks", "v1") |\> json\_response |\> Poison.decode! } end, then: fn ctx -\> assert 2 === length(ctx.result) end } end

    we could make us of with* step if we pretend to run the some tests for multiple input

     it "Ensures that add new track service works as expected" do %{ with: fn ctx -\> [%{new\_track: %{"title" =\> "Runaway", "singer" =\> "John Bon Jovi"}}, %{new\_track: %{"title" =\> "Let her go", "singer" =\> "The passenger"}},] end, given: &(%{new\_track\_json: &1.new\_track |\> Poison.encode!, previous\_tracks: build\_conn() |\> get("/tracks", "v1") |\> json\_response |\> Poison.decode! }), when: fn ctx -\> %{result: build\_conn() |\> put\_body\_or\_params(ctx.new\_track) |\> post("/tracks", "v1") |\> json\_response |\> Poison.decode! } end, then: fn ctx -\> assert length(ctx.previous\_tracks)+1 === length(ctx.result) assert true === Enum.member?(ctx.result, ctx.new\_track) end } end

    beforeEach : Before each will be inside of a scenario and provices with a reusable set of data for our tests.

     scenario "testing sum operation works as expected" do beforeEach do %{a: 10} end it "sum positive numbers works as expected" do %{ given: &(%{a: &1.a, b: 3}), when: &(%{c: &1.a + &1.b}), then: fn ctx -\> assert ctx.c === 13end } end it "sum negative numbers and it should work as expected" do %{ given: &(%{a: &1.a, b: -2}), when: &(%{c: sum(&1.a ,&1.b)}), then: fn ctx -\> assert ctx.c === 8end } endend

    First steps

    Once we have added exkorpion dependency to our test we can run the below command. This will creae a scenario directory on our poejct with a file named scenario_helper.exs.

     mix exkorpion.init

    By default Exkorpion will search files ended by " .._scenario.exs" inside directory scenarios. This could be easyly customized (We explain in following articles.)

    We can write one or more scenarios per file

    To run the exkorpion scenarios we just need to run

    MIX\_ENV=test mix exkorpion

    โœ… Exkorpion provides with a friendly resume about our tests execution.

    Success execution
    exkorpion success

    Something went wrong!
    exkorpion error


    It's highly recommendable you to have a look at some samples already developed: