Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add before/after Hooks for Efficient Testing #612

Open
jnst opened this issue Sep 13, 2023 · 1 comment
Open

Add before/after Hooks for Efficient Testing #612

jnst opened this issue Sep 13, 2023 · 1 comment

Comments

@jnst
Copy link

jnst commented Sep 13, 2023

Currently, I am utilizing runn with YAML to execute API tests, which includes the creation and cleanup of test data. The specific method of description is as follows:

steps:
  clean:
    db:
      query: |
        DELETE FROM
          product
        WHERE
          product_id = '{{ vars.product_id }}'
  create:
    db:
      query: |
        INSERT INTO product (
          product_id,
          name
        ) VALUES (
          '{{ vars.product_id }}',
          '{{ vars.name }}'
        )
  someTest:
    req:
      /products

However, using this method, the data in the table inevitably remains after the test execution.
Alternatively, if I move the clean step to the end and a test fails midway and is re-run, a duplicate key error occurs, making management difficult.

To alleviate this, I request the addition of a feature that allows the use of hooks commonly used in unit testing, such as before/after and beforeAll/afterAll.

before:
  create:
    db:
      query: |
        INSERT INTO product (
          product_id,
          name
        ) VALUES (
          '{{ vars.product_id }}',
          '{{ vars.name }}'
        )
after:
  clean:
    db:
      query: |
        DELETE FROM
          product
        WHERE
          product_id = '{{ vars.product_id }}'
steps:
  someTest:
    req:
      /products

This will likely enable more effective and efficient preparation and cleanup of test data.

@k1LoW
Copy link
Owner

k1LoW commented Sep 13, 2023

@jnst Thank you for your idea.

It's a similar issue to #397.

When runn is used as a Go package, BeforeFunc and AfterFunc are available.

We are cautious about providing before/after (or fail) in YAML for this issue because it does not offer the same flexibility as Go.

With the current functionality, something similar could be achieved using the force: section.

In any case, we'll consider it carefully.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants