Americium
Property-based testing for Scala and Java with integrated shrinkage. No need to write special-case shrinkers - Americium does it for you.
Get started now View it on GitHub
What is Americium?
Americium is a property-based testing library that automatically generates test cases and shrinks failing cases down to minimal reproducers. Unlike other property testing libraries, shrinkage is integrated - you donβt need to write separate shrinkers for your custom types.
Key Features
- Integrated Shrinkage - Automatic test case minimization with no extra code
- Multi-language - APIs for both Scala and Java
- Optional JUnit5 Integration - Deep integration with replay support
- Powerful DSL - Build complex test cases with map, flatMap, filter
- Recipe Reproduction - Reproduce any test case via recipe hash or JSON
Getting Started
Installation
Add Americium to your project:
Core library:
libraryDependencies += "com.sageserpent" %% "americium" % "2.0.0"
JUnit5 integration (optional):
libraryDependencies += "com.sageserpent" %% "americium-junit5" % "2.0.0"
Quick Example
import com.sageserpent.americium.Trials
val trials = Trials.api().integers(-5, 5)
trials.withLimit(10).supplyTo(println)
// Prints: 2, -5, 5, 4, 1, -4, 0, -3, -2, -1
When a test fails, Americium automatically shrinks the failing case:
val trials = Trials.api().integers()
trials.withLimit(1000).supplyTo { x =>
val xSquared = x * x
assertThat(xSquared / x, equalTo(x))
}
// Initial failure: x = 797772800
// After shrinkage: x = -46367 β Much easier to debug!
Quick Links
Philosophy
Americium believes that property-based testing should be accessible.
Thatβs why Americium:
- Provides a straightforward, composable API
- Handles shrinkage automatically
- Works with your existing test framework
- Gives you helpful reproduction recipes when tests fail
Community
- GitHub: sageserpent-open/americium
- Issues: Report bugs or request features
- Releases: View on Sonatype
License
Americium is distributed under the MIT License.