ProductPromotion
Logo

Elixir

made by https://0x3d.site

GitHub - wesovilabs/exkorpion: A BDD library for Elixir developers
A BDD library  for Elixir developers. Contribute to wesovilabs/exkorpion development by creating an account on GitHub.
Visit Site

GitHub - wesovilabs/exkorpion: A BDD library  for Elixir developers

GitHub - wesovilabs/exkorpion: A BDD library for Elixir developers

Build Status Hex version Hex downloads

Exkorpion

An Elixir framework to do testing in a BDD way

Installation

Library is available in Hex, the package can be installed as:

  1. Add exkorpion to your list of dependencies in mix.exs:
```elixir
def deps do
  [{:exkorpion, "~> 0.0.3"}]
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" do

       end

       it "sum negative numbers and it should work as expected" do

       end

    end

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

before_each: 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
  
    before_each 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 === 13
        end
      }
    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 === 8
        end
      }
    end

  end

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

Samples

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

Contributors

Articles
to learn more about the elixir concepts.

Resources
which are currently available to browse on.

mail [email protected] to add your project or resources here 🔥.

FAQ's
to know more about the topic.

mail [email protected] to add your project or resources here 🔥.

Queries
or most google FAQ's about Elixir.

mail [email protected] to add more queries here 🔍.

More Sites
to check out once you're finished browsing here.

0x3d
https://www.0x3d.site/
0x3d is designed for aggregating information.
NodeJS
https://nodejs.0x3d.site/
NodeJS Online Directory
Cross Platform
https://cross-platform.0x3d.site/
Cross Platform Online Directory
Open Source
https://open-source.0x3d.site/
Open Source Online Directory
Analytics
https://analytics.0x3d.site/
Analytics Online Directory
JavaScript
https://javascript.0x3d.site/
JavaScript Online Directory
GoLang
https://golang.0x3d.site/
GoLang Online Directory
Python
https://python.0x3d.site/
Python Online Directory
Swift
https://swift.0x3d.site/
Swift Online Directory
Rust
https://rust.0x3d.site/
Rust Online Directory
Scala
https://scala.0x3d.site/
Scala Online Directory
Ruby
https://ruby.0x3d.site/
Ruby Online Directory
Clojure
https://clojure.0x3d.site/
Clojure Online Directory
Elixir
https://elixir.0x3d.site/
Elixir Online Directory
Elm
https://elm.0x3d.site/
Elm Online Directory
Lua
https://lua.0x3d.site/
Lua Online Directory
C Programming
https://c-programming.0x3d.site/
C Programming Online Directory
C++ Programming
https://cpp-programming.0x3d.site/
C++ Programming Online Directory
R Programming
https://r-programming.0x3d.site/
R Programming Online Directory
Perl
https://perl.0x3d.site/
Perl Online Directory
Java
https://java.0x3d.site/
Java Online Directory
Kotlin
https://kotlin.0x3d.site/
Kotlin Online Directory
PHP
https://php.0x3d.site/
PHP Online Directory
React JS
https://react.0x3d.site/
React JS Online Directory
Angular
https://angular.0x3d.site/
Angular JS Online Directory