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!

πŸ“š Getting Started

Learn the basics of Americium

Read more β†’

πŸ§ͺ JUnit5 Integration

Use Americium with JUnit5

Read more β†’

πŸ’‘ Techniques

Advanced patterns and tricks

Read more β†’

πŸ”§ API Reference

Design and implementation details

Read more β†’

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


License

Americium is distributed under the MIT License.