Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/erlang.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,5 @@ jobs:
run: rebar3 eunit
- name: Run CT
run: rebar3 ct
- name: Generate docs
run: rebar3 ex_doc
56 changes: 56 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# nova_test

Testing library for [Nova](https://github.com/novaframework/nova) framework applications.

Provides an HTTP client for integration tests and a mock request builder for unit tests.

## Installation

Add `nova_test` to your test dependencies in `rebar.config`:

```erlang
{profiles, [
{test, [
{deps, [
{nova_test, "~> 0.1"}
]}
]}
]}.
```

## Usage

### Integration tests

Start the application under test and make HTTP requests:

```erlang
nova_test:start(),
{200, Headers, Body} = nova_test:get("/api/users", #{}).
```

### Assertion macros

Include the header for convenient assertions:

```erlang
-include_lib("nova_test/include/nova_test.hrl").

?assertStatus(200, Response),
?assertJson(#{<<"name">> => <<"alice">>}, Response),
?assertHeader(<<"content-type">>, <<"application/json">>, Response).
```

### Mock requests

Build mock Cowboy requests for unit-testing controllers without HTTP:

```erlang
Req = nova_test_request:new(<<"GET">>, <<"/users">>),
Req2 = nova_test_request:set_body(Req, <<"{\"name\":\"alice\"}">>),
Result = my_controller:handle(Req2).
```

## License

MIT
9 changes: 9 additions & 0 deletions rebar.config
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,15 @@
{nova, "~> 0.13"}
]}.

{project_plugins, [rebar3_ex_doc]}.

{hex, [{doc, #{provider => ex_doc}}]}.

{ex_doc, [{proglang, erlang},
{main, <<"readme">>},
{extras, [<<"README.md">>, <<"LICENSE">>]},
{source_url, <<"https://github.com/novaframework/nova_test">>}]}.

{profiles, [
{test, [
{erl_opts, [debug_info, nowarn_export_all]},
Expand Down