Features and Overview
AocKt (short for Advent of Code - Kotlin) is a simple library that makes running and testing your Kotlin solutions to Advent of Code puzzles a breeze.
It is an opinionated testing framework built on Kotest that defines a new AdventSpec
specialized for testing AoC puzzle solutions with minimal boilerplate.
✨ Features
Completely Offline - Puzzle inputs and solutions are read from local files, no need for tokens.
Test-Driven - Run your code from unit tests for faster feedback loops and fearless refactorings.
DSL-Driven - Define your test cases with minimal code.
Configurable - You decide what runs and when using optional parameters.
Minimal - The test framework is the only non-Kotlin dependency.
⚡ Quick Start
For your convenience, there is an advent-of-code-kotlin-template
repository which you can use to generate your own solutions repo. It comes with a pre-configured Gradle project with all bells and whistles you might need, as well as a modified source structure for easier navigation.
(If you need a working example, check out my solutions repo.)
To add AocKt to your existing project, simply add the dependencies and configure your unit tests to run with Kotest:
🧪 Test DSL Overview
AocKt provides the following DSL for testing puzzle solutions:
In the above example:
Your solution should implement the
Solution
interface.Each test class should be annotated with the
@AdventDay
annotation. Title is optional, but the year and day are required.Rather than passing it as an instance, the
AdventSpec
takes in your solution as a type parameter.Use the
partOne
andpartTwo
functions as needed. Inside the lambda you can define test cases. TheSolution
functions will only be invoked if the relevant part DSL is used. If you have not yet implemented the second part, or it doesn't exist (e.g.: Every year, part two of the last day just requires collecting all other 49 stars), then you may simply omit it.To define a test case, use the
shouldOutput
function. Each usage will define another test case. The value tested against is checked against its string value, soshouldOutput 4
andshouldOutput "4"
are equivalent.As a shorthand for defining multiple examples that should output the same thing, use the
shouldAllOutput
function.If you don't have any examples, but do want to run the part against your input the lambda can be omitted.