{"id":15638695,"url":"https://github.com/eed3si9n/verify","last_synced_at":"2025-04-05T09:07:04.700Z","repository":{"id":36126396,"uuid":"197225265","full_name":"eed3si9n/verify","owner":"eed3si9n","description":"Scala Verify is a minimal testing framework for Scala. Trust, but verify.","archived":false,"fork":false,"pushed_at":"2024-12-23T17:45:55.000Z","size":1320,"stargazers_count":93,"open_issues_count":26,"forks_count":21,"subscribers_count":6,"default_branch":"main","last_synced_at":"2025-03-29T08:07:12.900Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Scala","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/eed3si9n.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":"2019-07-16T15:58:40.000Z","updated_at":"2024-12-23T17:46:00.000Z","dependencies_parsed_at":"2023-02-16T23:31:23.610Z","dependency_job_id":"9a341ada-3cba-40d4-bd86-16e5f54d574f","html_url":"https://github.com/eed3si9n/verify","commit_stats":{"total_commits":508,"total_committers":41,"mean_commits":"12.390243902439025","dds":0.639763779527559,"last_synced_commit":"30ef4ea524b68cf77b494801e11ef37cef6a9b7d"},"previous_names":["scala/nanotest-strawman"],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eed3si9n%2Fverify","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eed3si9n%2Fverify/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eed3si9n%2Fverify/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eed3si9n%2Fverify/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/eed3si9n","download_url":"https://codeload.github.com/eed3si9n/verify/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247312078,"owners_count":20918344,"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":[],"created_at":"2024-10-03T11:22:30.956Z","updated_at":"2025-04-05T09:07:04.665Z","avatar_url":"https://github.com/eed3si9n.png","language":"Scala","funding_links":[],"categories":["测试"],"sub_categories":["语音合成"],"readme":"Verify\n======\n\nVerify is a minimalist unit testing framework, tracing its origins to [Minitest](https://github.com/monix/minitest) + [Expecty](https://github.com/eed3si9n/expecty) + [SourceCode](https://github.com/lihaoyi/sourcecode).\n\nIt is a small testing framework cross-compiled for Scala 2.11, 2.12, 2.13, Scala 3.x, [Scala.js](http://www.scala-js.org/) 0.6 and 1.0, and\n[Scala Native](https://www.scala-native.org/) 0.3.x and 0.4.0.\n\n## Usage in sbt\n\nFor `build.sbt` (use the `%%%` operator for Scala.js or Scala Native):\n\n```scala\n// use the %%% operator for Scala.js or Scala Native\nlibraryDependencies += \"com.eed3si9n.verify\" %% \"verify\" % \"1.0.0\" % Test\n\ntestFrameworks += new TestFramework(\"verify.runner.Framework\")\n```\n\n## Tutorial\n\n### BasicTestSuite\n\nTest suites MUST BE objects, not classes. To create a test suite without `setup` and `teardown`,\nextend [BasicTestSuite](shared/src/main/scala/verify/BasicTestSuite.scala) trait:\n\nHere's a simple test:\n\n```scala\nimport verify._\n\nobject SomethingTest extends BasicTestSuite {\n  test(\"addition\") {\n    assert(2 == 1 + 1)\n  }\n\n  test(\"failing test\") {\n    case class Person(name: String = \"Fred\", age: Int = 42) {\n      def say(words: String*) = words.mkString(\" \")\n    }\n    assert(Person().say(\"ping\", \"poing\") == \"pong pong\")\n  }\n\n  test(\"should throw\") {\n    class DummyException extends RuntimeException(\"DUMMY\")\n    def test(): String = throw new DummyException\n\n    intercept[DummyException] {\n      test()\n    }\n  }\n}\n```\n\nIn the context of `BasicTestSuite`, `assert(...)` function is wired up to power assertion,\nas known in Groovy. In the above, the failing test would result to the following:\n\n```\n- failing test *** FAILED ***\n  assertion failed\n\n  assert(Person().say(\"ping\", \"poing\") == \"pong pong\")\n         |        |                    |\n         |        ping poing           false\n         Person(Fred,42)\n    verify.asserts.PowerAssert$AssertListener.expressionRecorded(PowerAssert.scala:38)\n    verify.asserts.RecorderRuntime.recordExpression(RecorderRuntime.scala:39)\n    example.tests.SimpleTest$.$anonfun$new$9(SimpleTest.scala:54)\n```\n\n### assertions\n\nFor the most part, `assert(...)` should do the job.\n\nTo compare large strings, scala-verify also provides `assertEquals(expected: String, found: String, message: =\u003e String)`.\nIn case of an error, it will print the diff in color for easier detection of the differences.\n\n### setup and tearDown\n\nIn case you want to setup an environment for each test example and need `setup` and\n`tearDown` semantics, per test example, extend [TestSuite](shared/src/main/scala/verify/TestSuite.scala).\nThen on each `test` definition, you'll receive a fresh value:\n\n```scala\nimport verify.TestSuite\n\nobject SomethingTest extends TestSuite[Int] {\n  def setup(): Int = {\n    Random.nextInt(100) + 1\n  }\n\n  def tearDown(env: Int): Unit = {\n    assert(env \u003e 0, \"should still be positive\")\n  }\n\n  test(\"should be positive\") { env =\u003e\n    assert(env \u003e 0, \"positive test\")\n  }\n\n  test(\"should be lower or equal to 100\") { env =\u003e\n    assert(env \u003c= 100, s\"$env \u003e 100\")\n  }\n}\n```\n\nSome tests require setup and tear down logic to happen only once per test suite\nbeing executed and `TestSuite` supports that as well, but note you should abstain\nfrom doing this unless you really need it, since the per test semantics are much\nsaner:\n\n```scala\nobject SomethingTest extends TestSuite[Int] {\n  private var system: ActorSystem = _\n\n  override def setupSuite(): Unit = {\n    system = ActorSystem.create()\n  }\n\n  override def tearDownSuite(): Unit = {\n    TestKit.shutdownActorSystem(system)\n    system = null\n  }\n}\n```\n\n### asynchronous testing\n\nscala-verify supports asynchronous results in tests, use `testAsync` and\nreturn a `Future[Unit]`:\n\n```scala\nimport scala.concurrent.ExecutionContext.Implicits.global\n\nobject SomethingTest extends BasicTestSuite {\n  testAsync(\"asynchronous execution\") {\n    val future = Future(100).map(_+1)\n\n    for (result \u003c- future) yield {\n      assert(result == 101)\n    }\n  }\n}\n```\n\nThat's all you need to know.\n\n## Historical background\n\nVerify started out as an attempt to create a cross-platform, zero-dependency, minimal, testing framework for bootstrapping the toolchain and a small handful of foundational third-party libraries.\nSee https://github.com/scala/scala-dev/issues/641.\n\n## License\n\nAll code in this repository is licensed under the Apache License, Version 2.0.\nSee [NOTICE](./NOTICE).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Feed3si9n%2Fverify","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Feed3si9n%2Fverify","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Feed3si9n%2Fverify/lists"}