{"id":15684491,"url":"https://github.com/nathanielsimard/table-test","last_synced_at":"2025-05-07T17:28:44.492Z","repository":{"id":57669202,"uuid":"122558513","full_name":"nathanielsimard/table-test","owner":"nathanielsimard","description":"Improve table testing in Rust.","archived":false,"fork":false,"pushed_at":"2018-04-09T18:19:10.000Z","size":949,"stargazers_count":10,"open_issues_count":1,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-14T21:08:31.467Z","etag":null,"topics":["rust","rust-lang","testing"],"latest_commit_sha":null,"homepage":"","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/nathanielsimard.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-02-23T01:38:58.000Z","updated_at":"2024-10-16T23:22:46.000Z","dependencies_parsed_at":"2022-08-29T12:31:01.379Z","dependency_job_id":null,"html_url":"https://github.com/nathanielsimard/table-test","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nathanielsimard%2Ftable-test","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nathanielsimard%2Ftable-test/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nathanielsimard%2Ftable-test/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nathanielsimard%2Ftable-test/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nathanielsimard","download_url":"https://codeload.github.com/nathanielsimard/table-test/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252925960,"owners_count":21826226,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["rust","rust-lang","testing"],"created_at":"2024-10-03T17:17:58.169Z","updated_at":"2025-05-07T17:28:44.473Z","avatar_url":"https://github.com/nathanielsimard.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Table Test\n[![Build Status](https://travis-ci.org/nathanielsimard/table-test.svg?branch=master)](https://travis-ci.org/nathanielsimard/table-test)\n[![codecov.io](https://codecov.io/gh/nathanielsimard/table-test/coverage.svg?branch=master)](https://codecov.io/gh/nathanielsimard/table-test)\n[![Current Crates.io Version](https://img.shields.io/crates/v/table-test.svg)](https://crates.io/crates/table-test)\n\nThis library aims to make table testing reliable in Rust. \nThe main problem of table testing with basic Rust is `assert_eq!` calling `panic!`.\nIt means that when an assertion fails, then the rest of the test function is not executed.\nIn the case of a table test, it will result with potentially multiple use cases untested, making the output of that test unreliable.\n\n## Usage\n\nSpecify this crate as `[dev-dependencies]`.\n\n```toml\n[dev-dependencies]\ntable-test = \"0.2.1\"\n```\n\n```rust\n#[cfg(test)] // \u003c-- not needed in integration tests\n#[macro_use]\nextern crate table_test;\n```\n\nThe table iterator returns a tuple `(test_case, input, expected)`.\nIf you have more than one input, just use a tuple of inputs.\nThe `test_case` allows you to add comments like `given` `when` and `then`, but also `description` and `custom` giving you the freedom to log your tests the best way possible.\n\n## Examples\n\nIf we make a simple test for an `add` function that takes two values as input:\n\n```rust\n#[test]\nfn test_add() {\n    let table = vec![\n        ((1, 2), 3),\n        ((2, 5), 7),\n        ((0, 0), 0),\n        ((0, 1), 1),\n        ((2, 2), 4),\n    ];\n\n    for (validator, (input_1, input_2), expected) in table_test!(table) {\n        let actual = add(input_1, input_2);\n\n        validator\n            .given(\u0026format!(\"{}, {}\", input_1, input_2))\n            .when(\"add\")\n            .then(\u0026format!(\"it should be {}\", expected))\n            .assert_eq(expected, actual);\n    }\n}\n```\nIf we make a mistake in the implementation of the `add` function and multiplying instead, then the output will look like this:\n\n![multiple inputs](examples_outputs/multiple_inputs.png)\n\nAs we can see, it would be easier to debug than with a normal `assert_eq!` output.\nBut the gain is when we work with something more complex.\nThe example [here](examples/mutable_struct.rs) test the changing name method and the result looks like this:\n\n![mutable struct](examples_outputs/mutable_struct.png)\n\nMore examples can be found in the examples folder.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnathanielsimard%2Ftable-test","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnathanielsimard%2Ftable-test","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnathanielsimard%2Ftable-test/lists"}