sweet 0.1.9

Declarative testing framework
Documentation

sweet

Very early stage warning! No ongoing maintenance is guaranteed

Basically a jest clone, the sweet crate will set you up with a beautiful test harness and intuitive matchers that are easy on the eyes.

pub use sweet::*;

sweet! {
  it "works" {
    assert!("regular assertions and panics".len() > 0);

    expect("custom matchers").to_contain("custom")?;
  }
}

Quickstart

  1. edit cargo.toml
    [dev-dependencies]
    sweet = # current version here
    
    [[test]]
    name = "sweet"
    path = "test/sweet.rs"
    harness = false
    
  2. create file test/sweet.rs
    #![feature(imported_main)]
    pub use sweet::*;
    
    sweet! {
      it "works" {
        expect(true).to_be_false()?;
      }
    }
    
  3. run these commands
    rustup default nightly
    cargo test --test sweet
    

Features - Summary

  • Pretty Messages
    • Success
      • success
    • In progress
      • progress
    • Failure
      • failure

Features - Runner

  • Mutable globals

    • When writing lots of tests its helpful to have access to an outer scope
     sweet! {
     	let mut a = 0;
     	before {
     		a = a + 1;
     	}
     	test "before" {
     		expect(a).to_be(1)?;
     	}
     }
    
  • Automatic suite names

    • Unless otherwise defined, sweet suites will be named after the files:
     //named after file
     sweet!{
       it "works"{}
     }
     //custom name
     sweet!{ "My Test"
     	it "works"{}
     }
    
  • Nested Tests

    • Sweet is designed to collect and run all tests in one go. All tests exposed in the sweet.rs file will be run:
       //test/sub_dir/some_test.rs
       sweet!{
         it "works" {
           expect(true).to_be_true();
         }
       }
       //test/sub_dir/mod.rs
       mod some_test
       //test/sweet.rs
       #![feature(imported_main)]
       pub use sweet::*;
       mod sub_dir;
      

Example Commands

  • Run
    • cargo test --test sweet
  • With watch
    • cargo watch -q -x 'test --test sweet -- -w'
    • Clears terminal on each run
    • Returns an exit code zero (cleaner output)
  • Specify filename
    • cargo test --test sweet -- my_test

Reference