tests

package module
v0.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 3, 2025 License: MIT Imports: 4 Imported by: 0

README

Arematics Banner

Test Initialization Utility

This repository provides a utility function to streamline the initialization and execution of Godog BDD (Behavior Driven Development) tests in Go projects. It introduces a reusable InitializeTests function to handle boilerplate code for running feature tests with dynamic steps and paths.

Features

  • Dynamic Scenario Initialization: Clean separation of initialization logic for each package.
  • Improved Usability: Reduces repetitive setup code for tests.
  • Colored Output Support: Provides clear and colored test summaries.

Getting Started

Installation

To use this utility, first ensure you have the required dependencies:

go get -t github.com/Arematics/go-tests
Usage Example

Here’s a basic structure on how to use the InitializeTests function:

package tests

import (
  "github.com/Arematics/go-tests"
	"github.com/cucumber/godog"
	"testing"
)

func TestAnyFeatures(t *testing.T) {
	tests.InitializeTests(t, InitializeScenario, "./example.feature", "Example Suite")
}

// InitializeScenario defines the setup for your feature's steps.
func InitializeScenario(ctx *godog.ScenarioContext) {
	ctx.Step(`^I have (\d+) apples$`, func(apples int) error {
		// Step implementation here
		return nil
	})
	ctx.Step(`^I eat (\d+) apples$`, func(apples int) error {
		// Step implementation here
		return nil
	})
}
Function Signature
func InitializeTests(t *testing.T, initializer func(ctx *godog.ScenarioContext), featurePath string, suiteName string)

Parameters:

  • t *testing.T: Active test reference to link the BDD suite to a test run.
  • initializer func(ctx *godog.ScenarioContext): Scenario initializer to register feature-specific steps dynamically.
  • featurePath string: Path to the .feature file containing the scenarios to execute.
  • suiteName string: A name for your test suite to make results identifiable.
Benefits

The InitializeTests function simplifies Godog-based projects with:

  • Separation of test logic and step initialization.
  • Easy reusability and reduced code duplication.

Code of Conduct

This project is governed by the MIT License

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Test *testing.T

Functions

func InitializeTests

func InitializeTests(t *testing.T, initializer func(ctx *godog.ScenarioContext), featurePath string, suiteName string)

InitializeTests is a generic utility to run Godog tests for any package. It reduces redundant initialization logic across packages.

Types

This section is empty.

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL