Skip to content

Commit

Permalink
Update test_function docs
Browse files Browse the repository at this point in the history
  • Loading branch information
MarkusPettersson98 committed Oct 16, 2023
1 parent 42e0c49 commit b0574cc
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 9 deletions.
31 changes: 26 additions & 5 deletions test/test-manager/README.me
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
# Writing tests for [MullvadVPN App](https://github.com/mullvad/mullvadvpn-app/)

The `test-manager` crate is where the tests for the [MullvadVPN
The `test-manager` crate is where end-to-end tests for the [MullvadVPN
App](https://github.com/mullvad/mullvadvpn-app/) resides. The tests are located
in different modules under `test-manager/src/tests/`.

## Getting started

Tests are regular Rust functions! Except that they are also `async` and are
marked with the `#[test_function]` attribute
Tests are regular Rust functions! Except that they are also `async` and marked
with the `#[test_function]` attribute

```rust
#[test_function]
Expand All @@ -19,8 +19,29 @@ pub async fn test(
}
```

A more detailed writeup on how the `#[test_function]` macro works is given as a
doc-comment in [test_macro::lib.rs](./test_macro/src/lib.rs).
The `test_function` macro allows you to write tests for the MullvadVPN App in a
format which is very similiar to [standard Rust unit
tests](https://doc.rust-lang.org/book/ch11-01-writing-tests.html). A more
detailed writeup on how the `#[test_function]` macro works is given as a
doc-comment in [test_macro::test_function](./test_macro/src/lib.rs).

If a new module is created, make sure to add it in
`test-manager/src/tests/mod.rs`.

### UI/Graphical tests

It is possible to write tests for asserting graphical properties in the app, but
this is a slightly more involved process. GUI tests are written in `Typescript`,
and reside in the `gui/test/e2e` folder in the app repository. Packaging of
these tests is also done from the `gui/` folder.

Assuming that a graphical test `gui-test.spec` has been bundled correctly, it
can be invoked from any Rust function by calling
`test_manager::tests::ui::run_test(rpc:
.., params: ..) -> Result<ExecResult,
Error>`

```rust
// Run a UI test. Panic if any assertion in it fails!
test_manager::tests::ui::run_test(&rpc, &["gui-test.spec"]).await.unwrap()
```
12 changes: 8 additions & 4 deletions test/test-manager/test_macro/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,10 @@ use syn::{AttributeArgs, Lit, Meta, NestedMeta};
///
/// # Examples
///
/// Create a standard test. Remember that [`test_function`] will inject `rpc`
/// and `mullvad_client` for us.
/// ## Create a standard test.
///
/// Remember that [`test_function`] will inject `rpc` and `mullvad_client` for
/// us.
///
/// ```
/// #[test_function]
Expand All @@ -52,8 +54,10 @@ use syn::{AttributeArgs, Lit, Meta, NestedMeta};
/// }
/// ```
///
/// Create a test which will run early in the test loop, won't perform any
/// cleanup, must succeed and will always run.
/// ## Create a test with custom parameters
///
/// This test will run early in the test loop, won't perform any cleanup, must
/// succeed and will always run.
///
/// ```
/// #[test_function(priority = -1337, cleanup = false, must_succeed = true, always_run = true)]
Expand Down

0 comments on commit b0574cc

Please sign in to comment.