Quick Start
This guide will help you get BerryCrush up and running quickly.
Prerequisites
Java 21 or later
Kotlin 2.0+ (for Kotlin DSL)
JUnit 6+ (JUnit Platform)
Gradle 8.0+ or Maven 3.9+
An OpenAPI specification for your API
Installation
Add the following to your build.gradle.kts:
dependencies {
testImplementation("org.berrycrush.berrycrush:core:1.1.0-SNAPSHOT")
testImplementation("org.berrycrush.berrycrush:junit:1.1.0-SNAPSHOT")
// For Spring Boot projects
testImplementation("org.berrycrush.berrycrush:spring:1.1.0-SNAPSHOT")
}
Add the following to your build.gradle:
dependencies {
testImplementation 'org.berrycrush.berrycrush:core:1.1.0-SNAPSHOT'
testImplementation 'org.berrycrush.berrycrush:junit:1.1.0-SNAPSHOT'
// For Spring Boot projects
testImplementation 'org.berrycrush.berrycrush:spring:1.1.0-SNAPSHOT'
}
Add to your pom.xml:
<dependencies>
<dependency>
<groupId>org.berrycrush.berrycrush</groupId>
<artifactId>core</artifactId>
<version>1.1.0-SNAPSHOT</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.berrycrush.berrycrush</groupId>
<artifactId>junit</artifactId>
<version>1.1.0-SNAPSHOT</version>
<scope>test</scope>
</dependency>
<!-- For Spring Boot projects -->
<dependency>
<groupId>org.berrycrush.berrycrush</groupId>
<artifactId>spring</artifactId>
<version>1.1.0-SNAPSHOT</version>
<scope>test</scope>
</dependency>
</dependencies>
Creating Your First Test
1. Create an OpenAPI specification
Place your OpenAPI spec in src/test/resources/petstore.yaml:
openapi: 3.0.3
info:
title: Pet Store API
version: 1.0.0
paths:
/api/pets:
get:
operationId: listPets
responses:
'200':
description: List of pets
content:
application/json:
schema:
type: array
items:
$ref: '#/components/schemas/Pet'
components:
schemas:
Pet:
type: object
properties:
id:
type: integer
name:
type: string
2. Create a scenario file
Create src/test/resources/scenarios/pet-api.scenario:
scenario: List all pets
when: I request the pets list
call ^listPets
then: I receive a list of pets
assert status 200
assert $.pets notEmpty
3. Create bindings
Create a bindings class to provide configuration:
import org.berrycrush.config.OpenApiSpecValue
import org.berrycrush.junit.BerryCrushBindings
class PetStoreBindings : BerryCrushBindings {
override fun getBindings(): Map<String, Any> {
return mapOf(
"default" to OpenApiSpecValue("petstore.yaml", "http://localhost:8080")
)
}
}
4. Create a test class
Create your JUnit 5 test class:
import org.berrycrush.junit.*
import org.junit.platform.suite.api.IncludeEngines
@IncludeEngines("berrycrush")
@BerryCrushScenarios(locations = ["scenarios/pet-api.scenario"])
@BerryCrushSpec(paths = ["petstore.yaml"])
@BerryCrushConfiguration(bindings = PetStoreBindings::class)
class PetApiTest
5. Run the test
Run your test using Gradle:
./gradlew test
You should see output indicating which scenarios passed or failed.
Next Steps
Learn about Custom Steps to create reusable step definitions
Explore Plugins to extend functionality
Check out Reporting for test report generation
See Tutorial for a complete walkthrough