{"id":25776566,"url":"https://github.com/RichardWarburton/lambda-behave","last_synced_at":"2025-02-27T06:06:42.717Z","repository":{"id":17741057,"uuid":"20582138","full_name":"RichardWarburton/lambda-behave","owner":"RichardWarburton","description":"A modern testing and behavioural specification framework for Java 8","archived":false,"fork":false,"pushed_at":"2022-02-22T08:44:21.000Z","size":487,"stargazers_count":254,"open_issues_count":41,"forks_count":52,"subscribers_count":18,"default_branch":"master","last_synced_at":"2025-02-26T11:12:08.275Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"http://richardwarburton.github.io/lambda-behave/","language":"Java","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/RichardWarburton.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","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":"2014-06-07T00:43:10.000Z","updated_at":"2025-02-16T14:25:30.000Z","dependencies_parsed_at":"2022-09-11T20:30:17.472Z","dependency_job_id":null,"html_url":"https://github.com/RichardWarburton/lambda-behave","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RichardWarburton%2Flambda-behave","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RichardWarburton%2Flambda-behave/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RichardWarburton%2Flambda-behave/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RichardWarburton%2Flambda-behave/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/RichardWarburton","download_url":"https://codeload.github.com/RichardWarburton/lambda-behave/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":240840103,"owners_count":19866167,"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":"2025-02-27T06:01:26.810Z","updated_at":"2025-02-27T06:06:42.698Z","avatar_url":"https://github.com/RichardWarburton.png","language":"Java","readme":"### Introduction\n\nIf you're a Java developer and you've seen the fluent, modern specification frameworks available in other programming languages such as spock or jasmine then Lambda Behave is for you. Its goal is to make testing a more pleasant experience than it currently is with junit.\n\nThe [changelog](https://raw.githubusercontent.com/RichardWarburton/lambda-behave/master/CHANGELOG.md) explains what features have been added in each release.\n\n### Fluent Specifications\n\nThe Lambda Behave Specification design has several goals in mind:\n\n* To read like plain English.\n* To encourage describing tests using long and descriptive sentences, rather than a few words.\n* An API that is fluent and discoverable nearly entirely through IDE auto-completion.\n\n```java\npublic class StackSpec {{\n\n    Stack\u003cInteger\u003e stack = new Stack\u003c\u003e();\n\n    describe(\"a stack\", it -\u003e {\n\n        it.isSetupWith(stack::clear);\n\n        it.isConcludedWith(stack::clear);\n\n        it.should(\"be empty when created\", expect -\u003e {\n            expect.that(stack).isEmpty();\n        });\n```\n\nThere are many, many, expectations builtin to the framework - not just `isEmpty()`.\n\nEvery specification suite starts its declaration using the `Suite.describe` method. From that point onwards your IDE should be able to auto-complete the domain specific language for declaring specifications, but just in case you want more information, here's the details.\n\n* If you want to specify a property about your system use `it.should`.\n* If you want describe an expectation of that property, use `expect.that`. This will get you to a fluent API restricted to the type of value that you're making the expectation about. The expectation system is based upon hamcrest. Lambda Behave doesn't compromise the ability to compose matchers in favour of fluency - if you want to compose in more complex flavours simply use `expect.that(value).is()` and then you can use regular Hamcrest matchers. In my experience this is a rare, albeit useful, breakout option.\n* If you want to setup or teardown data before or after each specification use `it.isSetupWith` and `it.isConcludedWith`.\n* If you want to setup or teardown data before or after each suite use `it.initializesWith` and `it.completesWith`.\n* Don't worry - I know some Java 8 lambdafied APIs don't deal with exceptions very well but you can throw exceptions in all our callbacks and the appropriate error will be reported, not just break the library.\n\n### Data Driven Specifications\n\nThe ability to parametrise specifications by different data inputs.\nData driven tests in TestNG or the `@Parameterized` junit annotation perform a similar task.\n`@Parameterized` only parameterises at the level of a class, whereas Lambda Behave parameterises at the level of a specification.\n\n```java\ndescribe(\"a pair of numbers\", it -\u003e {\n    it.uses(4, 2)\n      .and(6, 3)\n      .toShow(\"%d / %d is two\", (expect, x, y) -\u003e {\n          expect.that(x / y).is(2);\n      });\n});\n```\n\nThe API in Lambda Behave is both fluent and also type safe and doesn't rely on reflection magic.\nThe `uses` method is overloaded to allow a different number of columns of data to be used. It also supports taking\nstreams or lists of data as its inputs, rather than explicitly chaining individual values.\n\nNot only is the specification parameterised by the data, but the description is also parameterised, its name being interpreted as a format `String`.\nThe aforementioned test would output the following:\n\n```\na pair of numbers\n  4 / 2 is two\n  6 / 3 is two\n```\n### Generated Specifications\n\nLambda Behave can automatically generate testcases for your to test your code with, similar to quick check or scala check.\nThe Fluent API for this is similar to data driven specifications allows for control over the way that the values are generated\nand how many need to be generated. Here is an example of how to show that reversing a `String` twice returns the same `String`\nusing randomly generated test case values.\n\n```java\nit.requires(10)\n  .example(asciiStrings())\n  .toShow(\"reversing a String twice returns the original String\", (expect, str) -\u003e {\n      String same = new StringBuilder(str).reverse().reverse().toString();\n      expect.that(same).isEqualTo(str);\n  });\n```\n\nAll generated specifications follow this common pattern where;\n\n * The `require` clause expresses how many values to generate,\n * The `example` clause states what type of objects to generate and how to generate them, This is overloaded to allow multiple columns of testcase values to be generated.\n * The `toShow` clause behaves like a `toShow` clause for a data drive spec. It is type safe against the the different columns.\n So in the above example the paramter `str` will have had its type correctly inferred as `String`.\n\n### Downloading Lambda Behave\n\nIf you're using a maven project then you can download Lambda Behave using the following pom entry.\n\n```xml\n\u003cdependency\u003e\n    \u003cgroupId\u003ecom.insightfullogic\u003c/groupId\u003e\n    \u003cartifactId\u003elambda-behave\u003c/artifactId\u003e\n    \u003cversion\u003e0.4\u003c/version\u003e\n    \u003cscope\u003etest\u003c/scope\u003e\n\u003c/dependency\u003e\n```\n\nIf you're using a gradle project then you can use:\n\n```gradle\ntestCompile group: 'com.insightfullogic', name: 'lambda-behave', version: '0.3'\n```\n\nThere's also an [example project](https://github.com/RichardWarburton/lambda-behave/tree/lambda-behave-parent-0.3/lambda-behave-examples)\nand there's published [Javadoc](http://javadoc.insightfullogic.com/lambda-behave).\n\n### Junit Integration\n\nLambda Behave also offers a junit runner. This lets you easily integrate into existing your existing test suite, or the tests via an Eclipse, Intellij, Netbeans, Maven, Gradle or Ant. You just add an annotation to enable this,\nand it can be run through your normal tooling.\n\n```java\n@RunWith(JunitSuiteRunner.class)\npublic class StackSpec {{\n```\n### Lambdas - what the hell are they?\n\nConveniently I've written a [book](http://shop.oreilly.com/product/0636920030713.do?cmp=af-prog-books-videos-product_cj_9781491900154_%25zp') on Lambda expressions in Java 8 and the cleaner code they enable!\n\n### Licensing\n\nThis library is licensed under the liberal MIT license - see LICENSE for the\nfull details. This means that it's free for any use.\n\n### More Details and How to contribute\n\n[The wiki](https://github.com/RichardWarburton/lambda-behave/wiki) has more information.\n","funding_links":[],"categories":["Projects","测试","项目"],"sub_categories":["Testing","测试"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FRichardWarburton%2Flambda-behave","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FRichardWarburton%2Flambda-behave","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FRichardWarburton%2Flambda-behave/lists"}