Call your services as black boxes. Run the same script everywhere.

Write an API test once. Run it on mocks on your laptop, on the real services in CI, and as a load test, without changing a line.

bbrun is a small scripting language for calling services. A script says what it calls, shopApi, and never where that is: each environment says so. The same script is a test, or the logic of an operation inside a service.

checkout.bbrun
goal "A customer orders two travel mugs"

step "Look at the product" {
    shopApi.get("/products/P100")
    assert response.status == 200   // response: the last call's answer
    let product = response.body     // keep what you need
}

step "Place the order" {
    shopApi.post("/orders", {
        "productId": product.id,
        "quantity": 2
    })
    assert response.status == 201
    let order = response.body
    assert order.total == product.unitPrice * 2
}

step "Find it again" {
    shopApi.get("/orders/${order.id}")
    assert response.body.status == "confirmed"
}
terminal
$ bbrun checkout.bbrun --env test
✔ SUCCESS (128ms)
  Assertions: 4 passed, 0 failed
  Requests:   3

The name

bb is for black box

bbrun began as a tool for black box testing: checking a service only through what it shows on the outside, its requests and its answers.

The idea stayed and grew. In a bbrun script, everything the script calls is a black box: something you use without needing to know what is inside. An HTTP API, a queue, a database, a mail server or a mock of any of them is a name and its operations. What is behind the name can change. The script does not.

Two uses, one language

Run a test scenario, or run business logic

A script orchestrates calls to services. What you do with the outcome decides what the script is.

A test scenario

The bbrun command plays the part of a user of your API: it calls it, checks the answers and reports what passed. A folder of scripts is a suite; the same script is also a load test. The exit status is 0 or 1, so a pipeline stops on a failure.

tests/not-found.bbrun
goal "An order that does not exist is not found"

shopApi.get("/orders/does-not-exist")
assert response.status == 404
validate response.body as ApiError
assert response.body.code == "ORDER_NOT_FOUND"

Scenarios · Run it in CI

A business function

Inside a service, a script is a function: it receives the request, calls the services it needs, combines what they answer and returns a result. The service sends it to its caller. bbrun has no server of its own: the engine is a Java library, and a Java service embeds it, hands it the request and sends back what the script returns.

operations/get-order.bbrun
ordersApi.get("/records/${request.path.id}")
if response.status == 404 {
    status(404)
    return { "code": "ORDER_NOT_FOUND" }
}
Order order = response.body
if order.customerId != context.customerId {
    status(404)
    return { "code": "ORDER_NOT_FOUND" }
}
return order

A script as a function · Embedding it in a service

Where Order and ApiError are written

In both scripts, validate response.body as ApiError and Order order = response.body check the data against a model. Models are written once, in domain.json next to bbrun.yaml, in DRef:

domain.json
{
  "name": "shop",
  "version": "1.1.0",
  "models": [
    { "name": "Order", "properties": [
        { "name": "id", "type": "String", "required": true, "key": true },
        { "name": "total", "type": "Number", "required": true, "rules": [{ "type": "positive" }] },
        { "name": "status", "type": "String", "required": true } ] },
    { "name": "ApiError", "properties": [
        { "name": "code", "type": "String", "required": true, "key": true },
        { "name": "message", "type": "String" } ] }
  ]
}

Environments

The logic stays. The environment changes.

A script holds no address, no key and no token. bbrun.yaml says, for each environment, what stands behind each name: a mock, a local stand-in or the real service with its credentials. Switching environment is one option on the command line, and the script runs the same.

bbrun.yaml
defaultEnvironment: local

environments:
  local:                 # a mock
    resources:
      shopApi:
        type: mock

  test:                  # the real service
    resources:
      shopApi:
        baseUrl: "${SHOP_URL:-http://127.0.0.1:8080}"
        auth:
          type: bearer
          token: "${SHOP_TOKEN}"
terminal
$ bbrun checkout.bbrun
  goal  A customer orders two travel mugs
  step  Look at the product
  step  Place the order
  step  Find it again
✔ SUCCESS (18ms)

$ bbrun checkout.bbrun --env test --verbose
  step  Look at the product
  call  shopApi.get /products/P100 → 200 (51 ms)
  step  Place the order
  call  shopApi.post /orders → 201 (7 ms)
  step  Find it again
  call  shopApi.get /orders/f4f3c5b2-17b6… → 200 (7 ms)
✔ SUCCESS (128ms)

Environments and resources

What a script can call

Every resource is a name and its operations

  • HTTP API

    api.get, post, put, patch, delete on real paths. Bearer, basic, API key and OAuth2 client credentials are handled under the name.

  • Mock

    The same names, answered from routes you write: fixed data, a file, an expression over the request, or a script.

  • Database

    db.query("select …", [id]) and db.execute(…) on PostgreSQL, MySQL, MariaDB, SQL Server or Oracle, or an embedded database for a local run.

  • Queue

    jobs.send(payload), receive(), peek().

  • Email and files

    mail.send({…}) and its outbox() to check; files.get, put, list, delete.

  • Your own services

    A service that runs scripts gives them services of its own, called like the others: kfig.set("payments.limit", 500).

What it is built on

Three open source parts, each with one job

bbrun

The language and the bbrun command: one executable that runs scenarios, suites and load tests. The same engine runs scripts inside a service.

iconn

Opens what the scripts call. bbrun hands each resource of the environment to iconn, which connects to the real service or stands in for it: an HTTP endpoint, an embedded database, a queue, a mailbox, a folder.

DRef

Says what the data must look like. validate order as Order checks a value against your model, and a mapping turns a provider's answer into your own shape before the script uses it.

Get started

Install it, run a script

bbrun is one executable for macOS and Linux, with nothing else to install. bbrun init writes a first project that runs on a mock, so there is no service to start and no file to write by hand.

terminal
$ brew install STRIMS-AB/tap/bbrun

$ bbrun init shop
  wrote shop/bbrun.yaml
  wrote shop/checkout.bbrun
  wrote shop/mocks/shopApi.yaml

$ cd shop && bbrun checkout.bbrun
  goal  A customer buys two travel mugs and finds the order afterwards
  step  Look at the product
  step  Place the order
  step  Find it again

✔ SUCCESS (18ms)
  Assertions: 6 passed, 0 failed
  Requests:   3