Simple testing library for rust.
To create a simple test, write the following:
cappuccino::tests!({
it should_something() {
assert_eq!(42, 42);
}
});
The keyword it
is used to describe a single test.
it should_something() {
assert_eq!(42, 42);
}
it should_something() -> Result<(), String> {
assert_eq!(42, 42);
Ok(())
}
async fn the_long_waited_answer() -> i32 {
// after seven and a half million years...
42
}
it should_something() async {
assert_eq!(the_long_waited_answer().await, 42);
}
async fn the_long_waited_answer() -> i32 {
// after seven and a half million years...
42
}
it should_pass_and_return_result() async -> Result<(), String> {
assert_eq!(the_long_waited_answer().await, 42);
Ok(())
}
it "should something" {
assert_eq!(42, 42);
}
NB: this will break the IDE test runner position for that test.
The keyword it
is used to describe a scenario.
when condition() {
it should_something() {
assert_eq!(42, 42);
}
it should_something_too() {
assert_eq!(42, 42);
}
}
NB: scenarios automatically import outer imports and functions:
fn the_answer() -> i32 {
42
}
when condition() {
it should_something() {
assert_eq!(the_answer(), 42);
}
}
when condition() {
when another_condition() {
it should_something() {
assert_eq!(42, 42);
}
}
}
when condition() {
when another_condition() {
// content
}
it should_something() {
assert_eq!(42, 42);
}
}
when "condition" {
when "another condition" {
// content
}
}
The keyword before
is used to create a setup method within tests!
or when
context.
before {
let (a, b) = (42, 42);
}
it should_something() {
assert_eq!(a, b);
}
before
is automatically propagated inside nested
when if no inner before
is defined.
before {
let (a,b) = (42, 42);
}
when condition() {
it should_something() {
assert_eq!(a, b);
}
}