{"id":13413910,"url":"https://github.com/jgroeneveld/trial","last_synced_at":"2025-03-14T20:30:45.834Z","repository":{"id":33927322,"uuid":"37648978","full_name":"jgroeneveld/trial","owner":"jgroeneveld","description":"A simple assertion library for go","archived":false,"fork":false,"pushed_at":"2022-10-05T19:54:58.000Z","size":35,"stargazers_count":6,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2024-07-31T20:52:58.016Z","etag":null,"topics":["assertion-library","assertions","go","testing"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jgroeneveld.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":"2015-06-18T09:01:30.000Z","updated_at":"2022-10-05T19:52:45.000Z","dependencies_parsed_at":"2022-09-14T01:01:51.569Z","dependency_job_id":null,"html_url":"https://github.com/jgroeneveld/trial","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jgroeneveld%2Ftrial","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jgroeneveld%2Ftrial/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jgroeneveld%2Ftrial/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jgroeneveld%2Ftrial/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jgroeneveld","download_url":"https://codeload.github.com/jgroeneveld/trial/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243641999,"owners_count":20323947,"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":["assertion-library","assertions","go","testing"],"created_at":"2024-07-30T20:01:52.548Z","updated_at":"2025-03-14T20:30:45.558Z","avatar_url":"https://github.com/jgroeneveld.png","language":"Go","readme":"# Trial [![GoDoc](https://godoc.org/github.com/jgroeneveld/trial/assert?status.svg)](https://godoc.org/github.com/jgroeneveld/trial/assert) [![GoReport](https://goreportcard.com/badge/github.com/jgroeneveld/trial)](https://goreportcard.com/report/github.com/jgroeneveld/trial)\n\nA simple assertion library for go. Also see [schema](https://github.com/jgroeneveld/schema) for easier JSON Schema testing.\n\n[GoCover](https://gocover.io/github.com/jgroeneveld/trial/assert)\n\n## Motivation\n\ngo-test is fine. We do not need big testing frameworks for most projects. \nOne thing its lacking though is simple assertions and ability to implement simple helpers as it does not allow us to skip\ntest logs.\n\nTrial gives us `th.Error(t testingT, skip int, msgs ...interface{})` allowing to skip callers to implement helpers with nice logging.\n\nFor most uses, the `trial/assert` package is enough, giving us the most basic assertions needed with nice error messages.\n\n## trial/assert Usage\n\n**Simple equals**\n\n```\nimport \"github.com/jgroeneveld/trial/assert\"\n\nassert.Equal(t, 1, 2)\n\nOutput:\nunit_test.go:42: Not equal:\n\t\tExpected: 1\n\t\t  Actual: 2\n```\n\n\n**Additional arguments** to overwrite the message\n\n```\nassert.Equal(t, 1, 2, \"numbers dont match for %q\", \"my param\")\n\nOutput:\nunit_test.go:42: numbers dont match for \"my param\":\n\t\tExpected: 1\n\t\t  Actual: 2\n```\n\n\n**Type problems** are made clear\n\n```\nassert.Equal(t, 1, int64(1))\n\nunit_test.go:42: Not equal:\n\t\tExpected: 1\n\t\t  Actual: 1\n\t\t   Types: Expected:int, Actual:int64\n```\n\nSee [example/example_test.go](example/example_test.go) for more.\n\n### Supported Assertions\n\n**Basic assertions**\n\n```\nEqual(expected, actual, msgf...)\nMustBeEqual(expected, actual, msgf...)\nNotEqual(expected, actual, msgf...)\nMustNotBeEqual(expected, actual, msgf...)\nDeepEqual(expected, actual, msgf...)\nMustBeDeepEqual(expected, actual, msgf...)\nTrue(expression bool, msgf...)\nMustBeTrue(expression bool, msgf...)\nFalse(expression bool, msgf...)\nMustBeFalse(expression bool, msgf...)\nNil(expression, msgf...)\nMustBeNil(expression, msgf...)\nNotNil(expression, msgf...)\nMustNotBeNil(expression, msgf...)\n```\n\n**JSON Schema assertions**\n\n```\nJSONSchema(reader, matcher, msgf...)\nMustMatchJSONSchema(reader, matcher, msgf...)\n```\n\n## Writing your own assertions\n`th` can be used to write simple own assertions. This for example gives you a wrapper for [schema](https://github.com/jgroeneveld/schema).MatchJSON to have simple JSON schema assertions in your tests:\n\n```go\nfunc AssertJSONSchema(t *testing.T, matcher schema.Matcher, r io.Reader) {\n\terr := schema.MatchJSON(matcher, r)\n\tif err != nil {\n\t\tth.Error(t, 1, err.Error())\n\t}\n}\n\nfunc MustMatchJSONSchema(t *testing.T, matcher schema.Matcher, r io.Reader) {\n\terr := schema.MatchJSON(matcher, r)\n\tif err != nil {\n\t\tth.Error(t, 1, err.Error())\n\t\tt.FailNow()\n\t}\n}\n```\n\n","funding_links":[],"categories":["测试相关","Testing","测试","Testing Frameworks","测试相关`测试库和测试数据集生成库`","Template Engines"],"sub_categories":["查询语","Testing Frameworks","HTTP客户端","HTTP Clients"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjgroeneveld%2Ftrial","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjgroeneveld%2Ftrial","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjgroeneveld%2Ftrial/lists"}