lovef / kotlin-assert-utils Goto Github PK
View Code? Open in Web Editor NEWA set of assert utilities for JUnit testing with Kotlin
License: Apache License 2.0
A set of assert utilities for JUnit testing with Kotlin
License: Apache License 2.0
0 isLessThan null
Would output:
java.lang.AssertionError:
Expected not: null
Got: null
It would be helpful if it would be
java.lang.AssertionError: 0 < null
intArrayOf(1, 2, 3) shouldEqual intArrayOf(4, 5, 6)
Should give
Expected: [4, 5, 6]
Got: [1, 2, 3]
Should fix new names that are less ambigous, especially for .isNull()
Given:
{ throw Exception() } throws Error::class
The above assertion should fail and print the actual exception that is thrown.
Actual: Only the not thrown exception is logged: se.lovef.assert.NotThrownError: Error was never thrown
Consider renaming assertion methods for better consistency and less ambiguity
a isEqualTo b
a shouldEqual b
a referenceIsEqualTo b
a shouldBe b
a doesContain b
a shouldContain b
a.isNull()
a.shouldBeNull()
a.isNotNull()
a.shouldNotBeNull()
a.isTrue()
a.shouldBeTrue()
A successful call to typeIs
should return the object as the expected type. Eg
a typeIs String::class
should return a
cast to String
(non nullable) if assertion holds true.
emptyList().shouldBeEmpty()
assertion
Add throws
method that asserts that a specific exception instance is thrown, practical for mocking.
val exception = Exception()
whenever(mocked.foo()) doThrow exception
{ mocked.foo() } throws exception
Comparing eg enum to string will fail with difficult to understand error message
enum class Foo {
BAR
}
@Test fun fooBar() {
Foo.BAR shouldEqual "BAR"
}
Outputs
java.lang.AssertionError:
Expected: BAR
Got: BAR
Suggestion:
Expected: <String> BAR
Got: <Foo> BAR
If types are equal then they may be omitted in error message
listOf(1, 2, 3) doesContain 1 doesContain 2 doesContain 3
doesContain
support for Any type. Eg
"value 123" doesContain 123 doesNotContain 1234
"abc" doesContain x // Same as "abc" doesContain x.toString(), or "$x"
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.