
Facilitates comprehensive testing of `equals()`, `hashCode()`, `compareTo`, and `toString()` methods. Features advanced checks for equality groups, collections, and `Comparable` implementations.
Automatic tester for equals(), hashCode(), compareTo(), and toString() methods of a class.
Similar to Guava's EqualsTester, but designed for Kotlin Multiplatform with enhanced validation features.
testEquality {
group(User("alex"), User("alex"), User("alex"))
group(User("sergey"), User("sergey"))
// User("page") is instantiated multiple times (default is 2).
// Can be customized via defaultGroupSize.
group { User("page") }
}maxIterations, all combinations are tested exhaustively. Otherwise, randomized testing is used to keep execution time reasonable.implementation("io.github.adokky:equals-tester:1.1.0")null returns false.false.hashCode() return consistent results.Comparable object compared to itself returns 0.0 when compared.For objects implementing List, Map, or Set:
If checkToString is enabled:
toString() results.toString() results.testEquality {
// Whether to require that no two objects in the same group are identical (===). Default: false
requireNonIdentical = true
// Maximum number of test iterations before switching to random sampling. Default: 100_000
maxIterations = 1000
// Default number of instances generated by factory functions. Default: 2
defaultGroupSize = 3
// Whether to check toString() consistency with equals(). Default: false
checkToString = true
// Whether to check Collection contract compliance (List, Map, Set). Default: true
checkCollectionContracts = true
// Whether to check Comparable contract compliance. Default: true
checkComparable = true
// Group with predefined equal objects
group(User("alex", 25), User("alex", 25))
// Group using factory function (creates defaultGroupSize instances)
group { index -> User("user", 30) }
// Group from list
group(listOf(User("bob", 35), User("bob", 35)))
// Group with explicit size
groupOfSize(5) { index -> User("user", 30) }
// Named groups (names are used in error messages)
namedGroup("test group", User("alex", 25), User("alex", 25))
namedGroup("test group", listOf(User("charlie", 45), User("charlie", 45)))
namedGroup("special users") { index -> User("special", 40) }
namedGroup("admin users", size = 2) { index -> User("admin", 50) }
}Automatic tester for equals(), hashCode(), compareTo(), and toString() methods of a class.
Similar to Guava's EqualsTester, but designed for Kotlin Multiplatform with enhanced validation features.
testEquality {
group(User("alex"), User("alex"), User("alex"))
group(User("sergey"), User("sergey"))
// User("page") is instantiated multiple times (default is 2).
// Can be customized via defaultGroupSize.
group { User("page") }
}maxIterations, all combinations are tested exhaustively. Otherwise, randomized testing is used to keep execution time reasonable.implementation("io.github.adokky:equals-tester:1.1.0")null returns false.false.hashCode() return consistent results.Comparable object compared to itself returns 0.0 when compared.For objects implementing List, Map, or Set:
If checkToString is enabled:
toString() results.toString() results.testEquality {
// Whether to require that no two objects in the same group are identical (===). Default: false
requireNonIdentical = true
// Maximum number of test iterations before switching to random sampling. Default: 100_000
maxIterations = 1000
// Default number of instances generated by factory functions. Default: 2
defaultGroupSize = 3
// Whether to check toString() consistency with equals(). Default: false
checkToString = true
// Whether to check Collection contract compliance (List, Map, Set). Default: true
checkCollectionContracts = true
// Whether to check Comparable contract compliance. Default: true
checkComparable = true
// Group with predefined equal objects
group(User("alex", 25), User("alex", 25))
// Group using factory function (creates defaultGroupSize instances)
group { index -> User("user", 30) }
// Group from list
group(listOf(User("bob", 35), User("bob", 35)))
// Group with explicit size
groupOfSize(5) { index -> User("user", 30) }
// Named groups (names are used in error messages)
namedGroup("test group", User("alex", 25), User("alex", 25))
namedGroup("test group", listOf(User("charlie", 45), User("charlie", 45)))
namedGroup("special users") { index -> User("special", 40) }
namedGroup("admin users", size = 2) { index -> User("admin", 50) }
}