{"id":17180608,"url":"https://github.com/houzuoguo/mut","last_synced_at":"2025-10-09T04:09:12.697Z","repository":{"id":141901362,"uuid":"3955624","full_name":"HouzuoGuo/MUT","owner":"HouzuoGuo","description":"MUT makes testing your Scala class instance state-transition a lot more easier.","archived":false,"fork":false,"pushed_at":"2012-04-09T00:47:19.000Z","size":108,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-01-30T03:13:04.261Z","etag":null,"topics":["scala","testing"],"latest_commit_sha":null,"homepage":"","language":"Scala","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/HouzuoGuo.png","metadata":{"files":{"readme":"README","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2012-04-07T04:05:27.000Z","updated_at":"2013-12-05T18:02:32.000Z","dependencies_parsed_at":"2023-03-13T10:27:46.007Z","dependency_job_id":null,"html_url":"https://github.com/HouzuoGuo/MUT","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/HouzuoGuo%2FMUT","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/HouzuoGuo%2FMUT/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/HouzuoGuo%2FMUT/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/HouzuoGuo%2FMUT/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/HouzuoGuo","download_url":"https://codeload.github.com/HouzuoGuo/MUT/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245372365,"owners_count":20604490,"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":["scala","testing"],"created_at":"2024-10-15T00:29:58.126Z","updated_at":"2025-10-09T04:09:07.649Z","avatar_url":"https://github.com/HouzuoGuo.png","language":"Scala","funding_links":[],"categories":[],"sub_categories":[],"readme":"MUT - A more interesting way to test your Scala classes.\n\n==== Idea ====\nUsing MUT, rather than writing specifications to test a class, you write\nspecifications to test how one (or a few) class instance(s) behave in\ndifferent states.\n\n==== Why use MUT ====\nSuppose that you have a class which has:\n- Operations (change the state of class)\n- Specifications (documented behaviors of class in different states)\nAnd the state of class is determined by the value of the class attributes.\nThere are two specifications which from two perspectives define the behavior\nof an operation that transforms the class instance's state from S1 to S2\nthen to S3.\nOur goal is to verify the correctness of the class instance in each of the\nstates against the two specifications.\nUsing the popular unit testing tools, such as ScalaCheck, ScalaTest, specs2,\nyou may need to write four tests:\nTest 1 - setup an instance at state S1 and test against spec 1\nTest 2 - setup an instance at state S1, execute the operation to change the\nstate to S2 then test against spec 1\nTest 3 - setup an instance at state S1, execute the operation to\nchange to state to S2, execute again to chance to state S3 then test against\nspec 1.\nTest 4 - setup an instance at state S1 and test against spec 2\n\nMUT is thus designed to eliminate the need of the repetitive class instance\nsetup and states transition. The above three tests will be written as the\nfollowing MUT test:\n\ntest(\"Test 1\") { // instance now at state 1\n  test against spec 1\n}\nnext(\"Test 2\") { // instance now at state 2\n  execute the operation\n  test against spec 1\n}\nnext(\"Test 3\") { // instance now at state 3\n  execute the operation\n  test against spec 1\n}\ntest(\"Test 4\") { // instance now at state 1\n  test against spec 2\n}\ncleanup\n\n==== How To Use MUT ====\nclass MyMutTest extends MUT {\n  var instance: MyClass = null\n  override def setup {\n    // Setup your instance(s)\n    instance = new MyClass\n  }\n  override def cleanup {\n    // Clean up for the whole test\n    if (instance != null) // You must have this line\n      instance.close().deleteTempFile()\n  }\n  test(\"Spec1 - instance should behave like A\") {\n    instance.operation(123)\n    if (instance state is like A)\n      true\n    else\n      false\n  } otherwise {\n    // Help to diagnose the problem when the preceding block falsed\n    println(\"instance has the incorrect state because of GGG\")\n    // Skip all the following \"next(){}\" tests\n    halt(\"Very serious error!! Shall not proceed to the next state tests!\")\n  }\n  next(\"Sepc1 - instance should behave like B\") {\n    instance.operation(234)\n    if (instance state is like B)\n      true\n    else\n      false\n  } otherwise { println(\"instance has the incorrect state\") }\n  // Following \"test(){}\", You can have any number of \"next(){}\" tests\n  // \"otherwise{}\" block is not compulsory\n  next(\"...\") { ... }\n  // Call \"test(){}\" will cleanup then re-setup\n  test(\"Spec2 - instance should behave like C\") {\n    ...\n  }\n  // You can also use \"timeTest\" and \"timeNext\" instead of \"test\" and \"next\"\n  // to print out the time taken to complete the test.\n  cleanup // Do not forget this line\n}\n==== Author ====\nHouzuo (Howard) Guo\nhttp://twitter.com/#!/hzguo\nhttp://www.linkedin.com/pub/houzuo-guo/27/b62/2b1\nhttps://github.com/HouzuoGuo\n\n==== License ====\nUse the source code in anyway you want, but please retain the author\ninformation, in case the user of your test code needs technical support.\n\n==== Background ====\nThe idea of MUT originated from designing a testing tool for my pet Scala\nproject ScalaDB:\nflat file DB engine in Scala - https://github.com/HouzuoGuo/ScalaDB\nUsage of MUT in the pet project is here:\nhttps://github.com/HouzuoGuo/ScalaDB/tree/master/src/test\n(Good place to have a look at how MUT is used in real scenarios)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhouzuoguo%2Fmut","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhouzuoguo%2Fmut","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhouzuoguo%2Fmut/lists"}