在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称(OpenSource Name):winterbe/expekt开源软件地址(OpenSource Url):https://github.com/winterbe/expekt开源编程语言(OpenSource Language):Kotlin 100.0%开源软件介绍(OpenSource Introduction):ExpektExpekt is a (work in progress) BDD assertion library for Kotlin, inspired by Chai.js. It works with your favorite test runner such as JUnit and Spek. class ExpektTest {
@Test
fun helloExpekt() {
23.should.equal(23)
"Kotlin".should.not.contain("Scala")
listOf(1, 2, 3).should.have.size.above(1)
}
}
Getting startedExpekt is available via Maven Central. Just add the dependency to your Maven POM or Gradle build config. Maven<dependency>
<groupId>com.winterbe</groupId>
<artifactId>expekt</artifactId>
<version>0.5.0</version>
<scope>test</scope>
</dependency> GradletestCompile "com.winterbe:expekt:0.5.0" IntroductionExpekt let's you write assertions in natural english language by building fluent sentences in your JUnit tests. It comes in two flavors When using IntelliJ IDEA you can simply use import com.winterbe.expekt.expect
import com.winterbe.expekt.should The Expekt API consists of many chainable properties and functions. Properties like See API doc for all available assertion properties and functions. What happens when expectations fail?When an expectation fails Expekt throws a class FailingTest {
@Test
fun thisTestFails() {
3.4.should.be.closeTo(3.2, delta = 0.1)
}
} The above test fails, resulting in the following exception:
ExamplesExample assertions using the 23.should.equal(23)
null.should.be.`null`
"foo".should.not.equal("bar")
3.should.satisfy { it % 2 == 1 }
3.should.be.above(2).and.below(4)
"abc".should.contain("bc").and.startWith("a")
"abc".should.not.have.length.above(3)
"abc".should.not.match(Regex("[0-9]+"))
listOf(1, 2, 3).should.contain(3).and.have.length.above(2)
listOf(1, 2, 3).should.contain.any.elements(1, 3, 4)
listOf(1, 2, 3).should.have.all.elements(1, 2, 3)
mapOf("foo" to "bar", "bar" to "foo").should.contain("foo" to "bar") Example assertions using the expect(23).to.equal(23)
expect(null).to.be.`null`
expect("foo").not.to.equal("bar")
expect(3).not.to.satisfy { it % 2 == 1 }
expect(3).to.be.above(2).and.to.be.below(4)
expect("abc").to.contain("bc").and.to.startWith("a")
expect("abc").not.to.have.length.above(3)
expect("abc").not.to.match(Regex("[0-9]+"))
expect(listOf(1, 2, 3)).to.contain(3).and.to.have.length.above(2)
expect(listOf(1, 2, 3)).to.contain.any.elements(1, 3, 4)
expect(listOf(1, 2, 3)).to.have.all.elements(1, 2, 3)
expect(mapOf("foo" to "bar", "bar" to "foo")).to.contain("foo" to "bar") LicenseMIT |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论