{"id":13770481,"url":"https://github.com/winterbe/expekt","last_synced_at":"2025-10-12T15:43:33.927Z","repository":{"id":37270893,"uuid":"51241300","full_name":"winterbe/expekt","owner":"winterbe","description":"BDD assertion library for Kotlin","archived":false,"fork":false,"pushed_at":"2022-06-20T22:40:49.000Z","size":83,"stargazers_count":172,"open_issues_count":11,"forks_count":18,"subscribers_count":9,"default_branch":"master","last_synced_at":"2025-07-11T17:05:34.963Z","etag":null,"topics":["assertions","bdd","junit","kotlin","test","unittest"],"latest_commit_sha":null,"homepage":"http://winterbe.github.io/expekt","language":"Kotlin","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/winterbe.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":"2016-02-07T08:48:52.000Z","updated_at":"2025-06-18T07:10:13.000Z","dependencies_parsed_at":"2022-09-04T15:10:37.077Z","dependency_job_id":null,"html_url":"https://github.com/winterbe/expekt","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"purl":"pkg:github/winterbe/expekt","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/winterbe%2Fexpekt","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/winterbe%2Fexpekt/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/winterbe%2Fexpekt/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/winterbe%2Fexpekt/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/winterbe","download_url":"https://codeload.github.com/winterbe/expekt/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/winterbe%2Fexpekt/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279011855,"owners_count":26085005,"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","status":"online","status_checked_at":"2025-10-12T02:00:06.719Z","response_time":53,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["assertions","bdd","junit","kotlin","test","unittest"],"created_at":"2024-08-03T17:00:38.073Z","updated_at":"2025-10-12T15:43:33.912Z","avatar_url":"https://github.com/winterbe.png","language":"Kotlin","readme":"# Expekt [![Travic CI](https://travis-ci.org/winterbe/expekt.svg?branch=master)](https://travis-ci.org/winterbe/expekt)\n\nExpekt is a (work in progress) BDD assertion library for [Kotlin](http://kotlinlang.org/), inspired by [Chai.js](http://chaijs.com/). It works with your favorite test runner such as [JUnit](http://junit.org/) and [Spek](http://jetbrains.github.io/spek/).\n\n```kotlin\nclass ExpektTest {\n    @Test\n    fun helloExpekt() {\n        23.should.equal(23)\n        \"Kotlin\".should.not.contain(\"Scala\")\n        listOf(1, 2, 3).should.have.size.above(1)\n    }\n}\n```\n\n\u003e [Follow on Twitter](https://twitter.com/winterbe_) for updates!\n\n### Getting started\n\nExpekt is available via [Maven Central](https://repo1.maven.org/maven2/com/winterbe/expekt/). Just add the dependency to your Maven POM or Gradle build config.\n\n##### Maven\n\n```xml\n\u003cdependency\u003e\n    \u003cgroupId\u003ecom.winterbe\u003c/groupId\u003e\n    \u003cartifactId\u003eexpekt\u003c/artifactId\u003e\n    \u003cversion\u003e0.5.0\u003c/version\u003e\n    \u003cscope\u003etest\u003c/scope\u003e\n\u003c/dependency\u003e\n```\n\n##### Gradle\n\n```groovy\ntestCompile \"com.winterbe:expekt:0.5.0\"\n```\n\n### Introduction\n\nExpekt let's you write assertions in natural english language by building fluent sentences in your JUnit tests.\n\nIt comes in two flavors `should` and `expect`, both exposing the same API. It's up to you which variant to use. The property `should` is available on any object (e.g. `myObject.should`), even on `null`. The function `expect` accepts any object as parameter (e.g. `expect(myObject)`) instead.\n\nWhen using IntelliJ IDEA you can simply use `expect` and `should` from classpath. The IDE handles all imports for you. In case you have to handle imports manually, add one of those to your test file:\n\n```kotlin\nimport com.winterbe.expekt.expect\nimport com.winterbe.expekt.should\n```\n\nThe Expekt API consists of many chainable properties and functions. Properties like `to`, `be` and `which` are provided to improve readibility. They don't serve any semantical meaning. The property `not` is used to negate expectations. Depending on the type of the initial value plenty of properties and functions are available to assert different aspects of the value, e.g. you can assert that a collection contains some elements, that a number is within it's bounds or that a string matches a given regex pattern.\n\nSee [API doc](APIDOC.md) for all available assertion properties and functions.\n\n### What happens when expectations fail?\n\nWhen an expectation fails Expekt throws a `java.lang.AssertionError` containing a readable message, so you can easily see what's going wrong.\n\n```kotlin\nclass FailingTest {\n    @Test\n    fun thisTestFails() {\n        3.4.should.be.closeTo(3.2, delta = 0.1)\n    }\n}\n```\n\nThe above test fails, resulting in the following exception:\n\n```\njava.lang.AssertionError: 3.4 should be closeTo 3.2 ±0.1\n\n\tat com.winterbe.expekt.ExpectAny.fail(ExpectAny.kt:77)\n\tat com.winterbe.expekt.ExpectAny.verify(ExpectAny.kt:68)\n\tat com.winterbe.expekt.ExpectDouble.closeTo(ExpectDouble.kt:12)\n\tat com.example.ExampleTest.example1(ExampleTest.kt:10)\n```\n\n### Examples\n\nExample assertions using the `should` property:\n\n```kotlin\n23.should.equal(23)\nnull.should.be.`null`\n\"foo\".should.not.equal(\"bar\")\n3.should.satisfy { it % 2 == 1 }\n3.should.be.above(2).and.below(4)\n\"abc\".should.contain(\"bc\").and.startWith(\"a\")\n\"abc\".should.not.have.length.above(3)\n\"abc\".should.not.match(Regex(\"[0-9]+\"))\nlistOf(1, 2, 3).should.contain(3).and.have.length.above(2)\nlistOf(1, 2, 3).should.contain.any.elements(1, 3, 4)\nlistOf(1, 2, 3).should.have.all.elements(1, 2, 3)\nmapOf(\"foo\" to \"bar\", \"bar\" to \"foo\").should.contain(\"foo\" to \"bar\")\n```\n\nExample assertions using the `expect` function:\n\n```kotlin\nexpect(23).to.equal(23)\nexpect(null).to.be.`null`\nexpect(\"foo\").not.to.equal(\"bar\")\nexpect(3).not.to.satisfy { it % 2 == 1 }\nexpect(3).to.be.above(2).and.to.be.below(4)\nexpect(\"abc\").to.contain(\"bc\").and.to.startWith(\"a\")\nexpect(\"abc\").not.to.have.length.above(3)\nexpect(\"abc\").not.to.match(Regex(\"[0-9]+\"))\nexpect(listOf(1, 2, 3)).to.contain(3).and.to.have.length.above(2)\nexpect(listOf(1, 2, 3)).to.contain.any.elements(1, 3, 4)\nexpect(listOf(1, 2, 3)).to.have.all.elements(1, 2, 3)\nexpect(mapOf(\"foo\" to \"bar\", \"bar\" to \"foo\")).to.contain(\"foo\" to \"bar\")\n```\n\n### License\n\nMIT","funding_links":[],"categories":["Unit Test","测试"],"sub_categories":["Library"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwinterbe%2Fexpekt","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwinterbe%2Fexpekt","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwinterbe%2Fexpekt/lists"}