{"id":16516229,"url":"https://github.com/aphistic/sweet","last_synced_at":"2025-03-21T08:31:46.722Z","repository":{"id":57479647,"uuid":"75155067","full_name":"aphistic/sweet","owner":"aphistic","description":"Sweet is a pluggable test runner capable of hooking into standard Go tests.","archived":false,"fork":false,"pushed_at":"2023-02-25T00:12:02.000Z","size":57,"stargazers_count":4,"open_issues_count":9,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-01T04:32:19.755Z","etag":null,"topics":["go","golang","sweet","testing","unit-testing"],"latest_commit_sha":null,"homepage":null,"language":"Go","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/aphistic.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2016-11-30T05:37:54.000Z","updated_at":"2024-06-21T11:57:14.000Z","dependencies_parsed_at":"2024-06-18T22:56:05.990Z","dependency_job_id":"e3a2faca-c5b0-4c67-9203-2155bab8bc68","html_url":"https://github.com/aphistic/sweet","commit_stats":{"total_commits":42,"total_committers":3,"mean_commits":14.0,"dds":0.2857142857142857,"last_synced_commit":"7e6e0a7c60bb017fabde01f9cfd64b8897194c11"},"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aphistic%2Fsweet","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aphistic%2Fsweet/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aphistic%2Fsweet/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aphistic%2Fsweet/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/aphistic","download_url":"https://codeload.github.com/aphistic/sweet/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244124198,"owners_count":20401685,"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":["go","golang","sweet","testing","unit-testing"],"created_at":"2024-10-11T16:20:10.976Z","updated_at":"2025-03-21T08:31:46.005Z","avatar_url":"https://github.com/aphistic.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# sweet\nSweet is a pluggable test runner capable of hooking into standard Go tests. It attempts to provide access to the standard Go test tool as close as possible while adding support for test suites and plugins that can hook into test results to add additional functionality.\n\n## Using Sweet\n\nTo use Sweet as your test runner you need to add the [TestMain](https://golang.org/pkg/testing/#hdr-Main) function from the Go `testing` package.  This will allow Sweet to run code before and after the actual tests run.  Inside the `TestMain` function you'll want to call the `sweet.Run` function to both set up the Sweet configuration as well as run the tests:\n\n``` Go\npackage mypackage\n\nimport (\n    \"testing\"\n    \"github.com/aphistic/sweet\"\n)\n\n\nfunc TestMain(m *testing.M) {\n    sweet.Run(m, func(s *sweet.S) {\n        // Configuration goes here\n    })\n}\n```\n\n## Defining a Suite\n\nA test suite in Sweet is just a normal Go struct with methods named similar to standard go test names (beginning with `Test`).  Creating a suite named `FailSuite` with a single test that always fails and then running it with Sweet looks like the following code:\n\n``` Go\npackage mypackage\n\nimport (\n    \"testing\"\n    \"github.com/aphistic/sweet\"\n)\n\n\nfunc TestMain(m *testing.M) {\n    sweet.Run(m, func(s *sweet.S) {\n        s.AddSuite(\u0026FailSuite{})\n        // Add any additional suites the same way\n    })\n}\n\ntype FailSuite struct {}\n\nfunc (s *FailSuite) TestAlwaysFails(t sweet.T) {\n    t.Fail()\n}\n```\n\n## Using a Plugin\n\nSweet supports plugins to add functionality that isn't typically available with the standard Go testing tools.  One such example is [sweet-junit](https://github.com/aphistic/sweet-junit), a plugin that generates a `junit.xml` file for each package it's used in. To add to the previous examples, this is how you'd add the `sweet-junit` plugin to your tests:\n\n``` Go\npackage mypackage\n\nimport (\n    \"testing\"\n    \"github.com/aphistic/sweet\"\n    junit \"github.com/aphistic/sweet-junit\"\n)\n\n\nfunc TestMain(m *testing.M) {\n    sweet.Run(m, func(s *sweet.S) {\n        s.RegisterPlugin(junit.NewPlugin())\n\n        s.AddSuite(\u0026FailSuite{})\n        // Add any additional suites the same way\n    })\n}\n\ntype FailSuite struct {}\n\nfunc (s *FailSuite) TestAlwaysFails(t sweet.T) {\n    t.Fail()\n}\n```\n\n## Using an External Matcher\n\nSweet was designed with the capability to use external matchers in mind.  You can write standard Go unit tests but you can also hook a different matcher library in and use that.\n\nSo far the only matcher that Sweet has been tested with and has hooks for is the [Gomega](https://onsi.github.io/gomega/) library.\n\nTo use `Gomega` in the above example, you would do:\n\n``` Go\npackage mypackage\n\nimport (\n    \"testing\"\n\n    . \"github.com/onsi/gomega\"\n\n    \"github.com/aphistic/sweet\"\n    junit \"github.com/aphistic/sweet-junit\"\n)\n\n\nfunc TestMain(m *testing.M) {\n    RegisterFailHandler(sweet.GomegaFail)\n\n    sweet.Run(m, func(s *sweet.S) {\n        s.RegisterPlugin(junit.NewPlugin())\n\n        s.AddSuite(\u0026FailSuite{})\n        // Add any additional suites the same way\n    })\n}\n\ntype FailSuite struct {}\n\nfunc (s *FailSuite) TestAlwaysFails(t sweet.T) {\n    t.Fail()\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faphistic%2Fsweet","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Faphistic%2Fsweet","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faphistic%2Fsweet/lists"}