### Install Allure Go Framework Source: https://github.com/ozontech/allure-go/blob/master/README.md Use this command to install the Allure Go framework package. ```bash go get github.com/ozontech/allure-go/pkg/framework ``` -------------------------------- ### Setup Hooks in Allure Go Source: https://github.com/ozontech/allure-go/blob/master/README.md Demonstrates how to use BeforeEach, AfterEach, BeforeAll, and AfterAll hooks in Allure Go test suites. These hooks allow setup and teardown actions before and after tests or test suites. ```go package examples import ( t"testing" "github.com/ozontech/allure-go/pkg/framework/provider" "github.com/ozontech/allure-go/pkg/framework/suite" ) type BeforeAfterDemoSuite struct { suite.Suite } func (s *BeforeAfterDemoSuite) BeforeEach(t provider.T) { t.NewStep("Before Test Step") } func (s *BeforeAfterDemoSuite) AfterEach(t provider.T) { t.NewStep("After Test Step") } func (s *BeforeAfterDemoSuite) BeforeAll(t provider.T) { t.NewStep("Before suite Step") } func (s *BeforeAfterDemoSuite) AfterAll(t provider.T) { t.NewStep("After suite Step") } func (s *BeforeAfterDemoSuite) TestBeforeAfterTest(t provider.T) { t.Epic("Demo") t.Feature("BeforeAfter") t.Title("Test wrapped with SetUp & TearDown") t.Description(` This test wrapped with SetUp and TearDown containert. `) t.Tags("BeforeAfter") } func TestBeforesAfters(t *testing.T) { tt.Parallel() suite.RunSuite(t, new(BeforeAfterDemoSuite)) } ``` -------------------------------- ### Go Test Setup and Teardown with Allure Source: https://github.com/ozontech/allure-go/blob/master/README.md Demonstrates how to use `WithTestSetup` and `WithTestTeardown` for initializing and cleaning up test resources within a test function. Use this for managing state before and after test execution. ```go package suite_demo import ( "context" "testing" "github.com/ozontech/allure-go/pkg/framework/provider" "github.com/ozontech/allure-go/pkg/framework/suite" ) type SetupSuite struct { suite.Suite } func (s *SetupSuite) TestMyTest(t provider.T) { var ( v1 string v2 int ctx context.Context ) t.WithTestSetup(func(t provider.T) { t.WithNewStep("init v1", func(sCtx provider.StepCtx) { v1 = "string" sCtx.WithNewParameters("v1", v1) }) t.WithNewStep("init v2", func(sCtx provider.StepCtx) { v2 = 123 sCtx.WithNewParameters("v2", v2) }) t.WithNewStep("init ctx", func(sCtx provider.StepCtx) { ctx = context.Background() sCtx.WithNewParameters("ctx", ctx) }) }) defer t.WithTestTeardown(func(t provider.T) { t.WithNewStep("Close ctx", func(sCtx provider.StepCtx) { ctx.Done() sCtx.WithNewParameters("ctx", ctx) }) }) } func TestRunner(t *testing.T) { suite.RunSuite(t, new(SetupSuite)) } ``` -------------------------------- ### Runner with Lifecycle Hooks Source: https://github.com/ozontech/allure-go/blob/master/pkg/framework/README.md Utilize this when you need to define setup and teardown logic for tests. Supports Before/After All/Each hooks. ```go package test import ( "testing" "github.com/ozontech/allure-go/pkg/framework/provider" "github.com/ozontech/allure-go/pkg/framework/runner" ) func TestMyTest(t *testing.T) { r := runner.NewRunner(t, t.Name()) r.BeforeAll(func(t provider.T) { // This will be executed before all tests start ... }) r.BeforeEach(func(t provider.T) { // This will be executed before each test start ... }) r.AfterEach(func(t provider.T) { // This will be executed after each test ... }) r.AfterAll(func(t provider.T) { // This will be executed when all tests over ... }) r.NewTest("My test 1", func(t provider.T) { // Test Body... }, "sampleTag1", "sampleTag2") r.RunTests() } ``` -------------------------------- ### Chained Method Calls Example Source: https://github.com/ozontech/allure-go/blob/master/pkg/allure/README.md Demonstrates how multiple step methods can be chained together for concise step definition and modification. ```APIDOC ## Example Usage ### Description This example shows how to create a step, add parameters, set its status to passed, and then finish it, all in a single chain of calls. ### Code ```go package test import ( "github.com/ozontech/allure-go/pkg/allure" "github.com/ozontech/allure-go/pkg/framework/provider" ) // ... func (s *SomeSuite) SomeTest(t provider.T) { step := allure.NewSimpleStep("My First Step").WithNewParameters("k1", "v1").Passed().Finish() t.Step(step) } ``` ``` -------------------------------- ### Basic Test Function with Runner Source: https://github.com/ozontech/allure-go/blob/master/pkg/framework/README.md Use this for simple test cases without complex setup. It runs a single test function with specified tags. ```go package test import ( t"testing" "github.com/ozontech/allure-go/pkg/framework/provider" "github.com/ozontech/allure-go/pkg/framework/runner" ) func TestMyTest(t *testing.T) { runner.Run(t, "My first test", func(t provider.T) { // test body... }, "sampleTag1", "sampleTag2") } ``` -------------------------------- ### Parametrized Test Example in Go Source: https://github.com/ozontech/allure-go/blob/master/pkg/framework/README.md Demonstrates how to define and run a parametrized test. Ensure your parameter slice name follows the 'Param' prefix convention and your test method uses the 'TableTest' prefix. ```go package suite_demo import ( "testing" "github.com/jackc/fake" "github.com/ozontech/allure-go/pkg/framework/provider" "github.com/ozontech/allure-go/pkg/framework/suite" ) type ParametrizedSuite struct { suite.Suite // ParamCities param has name as expected test but has prefix Param instead of TableTest ParamCities []string } func (s *ParametrizedSuite) BeforeAll(t provider.T) { for i := 0; i < 10; i++ { s.ParamCities = append(s.ParamCities, fake.City()) } } // TableTestCities is parametrized test has name prefix TableTest instead of Test func (s *ParametrizedSuite) TableTestCities(t provider.T, city string) { t.Parallel() t.Require().NotEmpty(city) } func TestNewParametrizedDemo(t *testing.T) { suite.RunSuite(t, new(ParametrizedSuite)) } ``` -------------------------------- ### Suite-Based Test Structure Source: https://github.com/ozontech/allure-go/blob/master/pkg/framework/README.md Ideal for organizing tests into logical suites with shared setup and teardown. Uses a struct to define test suite behavior. ```go package suite_demo import ( "testing" "github.com/ozontech/allure-go/pkg/framework/provider" "github.com/ozontech/allure-go/pkg/framework/suite" ) type SampleSuite struct { suite.Suite } func (s *SampleSuite) BeforeAll(t provider.T) { // This will be executed before all tests start ... } func (s *SampleSuite) AfterAll(t provider.T) { // This will be executed when all tests over ... } func (s *SampleSuite) BeforeEach(t provider.T) { // This will be executed before each test start ... } func (s *SampleSuite) AfterEach(t provider.T) { // This will be executed after each test ... } func (s *SampleSuite) TestBeforeAfterTest(t provider.T) { // Test Body ... } func TestRunner(t *testing.T) { suite.RunSuite(t, new(SampleSuite)) } ``` -------------------------------- ### Go: Manage Allure IDs with GetAllureID Source: https://github.com/ozontech/allure-go/blob/master/README.md Implement `GetAllureID` to manually assign Allure IDs to tests, ensuring they are reported even if setup fails. This is useful for common tests where parameters are not involved. ```go package suite_demo import ( "testing" "github.com/ozontech/allure-go/pkg/framework/provider" "github.com/ozontech/allure-go/pkg/framework/suite" ) type AllureIDSuite struct { suite.Suite } func (testSuit *AllureIDSuite) GetAllureID(testName string) string { switch testName { case "TestWithAllureIDFirst": return "9001" case "TestWithAllureIDSecond": return "9002" default: return "" } } func (s *AllureIDSuite) BeforeAll(t provider.T) { // code that can fail here } func (s *AllureIDSuite) TestWithAllureIDFirst(t provider.T) { // code of your test here } func (s *AllureIDSuite) TestWithAllureIDSecond(t provider.T) { // code of your test here } func TestNewDemo(t *testing.T) { suite.RunSuite(t, new(AllureIDSuite)) } ``` -------------------------------- ### Create a Simple Step with Parameters and Status Source: https://github.com/ozontech/allure-go/blob/master/pkg/allure/README.md Demonstrates chaining methods to create a simple step, add parameters, set its status to Passed, and mark it as finished. ```go package test import ( "github.com/ozontech/allure-go/pkg/allure" "github.com/ozontech/allure-go/pkg/framework/provider" ) // ... func (s *SomeSuite) SomeTest(t provider.T) { step := allure.NewSimpleStep("My First Step").WithNewParameters("k1", "v1").Passed().Finish() t.Step(step) } ``` -------------------------------- ### Run Multiple Suites in Parallel in Go Source: https://github.com/ozontech/allure-go/blob/master/README.md Demonstrates how to run multiple test suites in parallel using `s.RunSuite` for individual suites and `suite.RunSuite` for a collection of suites. This is useful for organizing and executing large test suites efficiently. ```go package examples import ( "testing" "github.com/ozontech/allure-go/pkg/framework/provider" "github.com/ozontech/allure-go/pkg/framework/suite" ) type TestRunningDemoSuite struct { suite.Suite } func (s *TestRunningDemoSuite) TestBeforesAfters(t provider.T) { t.Parallel() // use RunInner to run suite of tests s.RunSuite(t, new(BeforeAfterDemoSuite)) } func (s *TestRunningDemoSuite) TestFails(t provider.T) { t.Parallel() s.RunSuite(t, new(FailsDemoSuite)) } func (s *TestRunningDemoSuite) TestLabels(t provider.T) { t.Parallel() s.RunSuite(t, new(LabelsDemoSuite)) } func TestRunDemo(t *testing.T) { // use RunSuites to run suite of suites suite.RunSuite(t, new(TestRunningDemoSuite)) } ``` -------------------------------- ### Execute Allure Go Tests via Command Line Source: https://github.com/ozontech/allure-go/blob/master/README.md Command to run Go tests using the standard 'go test' command. Ensure your test files are correctly placed within the './test' directory. ```bash go test ./test/... ``` -------------------------------- ### Run Basic Tests with Allure Go Source: https://github.com/ozontech/allure-go/blob/master/README.md This Go code demonstrates how to define and run basic tests using the Allure Go framework's runner. It includes creating new steps and nested steps within tests. ```go package test import ( testing "github.com/ozontech/allure-go/pkg/framework/provider" "github.com/ozontech/allure-go/pkg/framework/runner" ) func TestRunner(t *testing.T) { runner.Run(t, "My first test", func(t provider.T) { t.NewStep("My First Step!") }) runner.Run(t, "My second test", func(t provider.T) { t.WithNewStep("My Second Step!", func(sCtx provider.StepCtx) { sCtx.NewStep("My First SubStep!") }) }) } ``` -------------------------------- ### Run a Test Suite with Allure Go Source: https://github.com/ozontech/allure-go/blob/master/README.md This Go code defines the main function to run a test suite using `suite.RunSuite`. It sets up the test environment for the suite. ```go package test import ( testing "github.com/ozontech/allure-go/pkg/framework/provider" "github.com/ozontech/allure-go/pkg/framework/suite" ) type MyFirstSuite struct { suite.Suite } func (s *MyFirstSuite) TestMyFirstTest(t provider.T) { t.NewStep("My First Step!") } func (s *MyFirstSuite) TestMySecondTest(t provider.T) { t.WithNewStep("My Second Step!", func(sCtx provider.StepCtx) { sCtx.NewStep("My First SubStep!") }) } func TestSuiteRunner(t *testing.T) { suite.RunSuite(t, new(MyFirstSuite)) } ``` -------------------------------- ### Run Async Test with Async Steps in Go Source: https://github.com/ozontech/allure-go/blob/master/README.md Demonstrates how to run parallel tests with asynchronous steps. Use `t.Parallel()` to enable parallel execution and `t.WithNewAsyncStep` to define asynchronous operations within a test. ```go package async import ( "fmt" "time" "github.com/ozontech/allure-go/pkg/framework/provider" "github.com/ozontech/allure-go/pkg/framework/suite" ) type AsyncSuiteStepDemo struct { suite.Suite } func (s *AsyncSuiteStepDemo) BeforeEach(t provider.T) { t.Epic("Async") t.Feature("Async Steps") t.Tags("async", "suite", "steps") } func (s *AsyncSuiteStepDemo) TestAsyncStepDemo1(t provider.T) { t.Title("Async Test with async steps 1") t.Parallel() t.WithNewAsyncStep("Async Step 1", func(ctx provider.StepCtx) { ctx.WithNewParameters("Start", fmt.Sprintf("%s", time.Now())) time.Sleep(3 * time.Second) ctx.WithNewParameters("Stop", fmt.Sprintf("%s", time.Now())) }) t.WithNewAsyncStep("Async Step 2", func(ctx provider.StepCtx) { ctx.WithNewParameters("Start", fmt.Sprintf("%s", time.Now())) time.Sleep(3 * time.Second) ctx.Logf("Step 2 Stopped At: %s", fmt.Sprintf("%s", time.Now())) ctx.WithNewParameters("Stop", fmt.Sprintf("%s", time.Now())) }) } ``` -------------------------------- ### Skipping Tests with XSkip Source: https://github.com/ozontech/allure-go/blob/master/README.md Demonstrates how to skip a test using `t.XSkip()` and an assertion that fails. This is useful for tests that are temporarily disabled or known to fail. ```go package examples import ( "testing" "github.com/stretchr/testify/require" "github.com/ozontech/allure-go/pkg/framework/provider" "github.com/ozontech/allure-go/pkg/framework/suite" ) type DemoSuite struct { suite.Suite } func (s *DemoSuite) TestXSkipFail(t provider.T) { t.Title("This test skipped by assert with message") t.Description(` This Test will be skipped with assert Error. Error text: Assertion Failed `) t.Tags("fail", "xskip", "assertions") t.XSkip() t.Require().Equal(1, 2, "Assertion Failed") } func TestDemoSuite(t *testing.T) { t.Parallel() suite.RunSuite(t, new(DemoSuite)) } ``` -------------------------------- ### Parameters Methods Source: https://github.com/ozontech/allure-go/blob/master/pkg/framework/README.md Methods for adding parameters to the current step. ```APIDOC ## WithParameters ### Description Adds a list of `allure.Parameter` to the current step. ### Method `WithParameters(parameters ...allure.Parameter) ### Parameters - `parameters` (...allure.Parameter) - The list of parameters to add. ## WithNewParameters ### Description Creates new parameters from key-value pairs. Odd arguments are treated as keys, and even arguments as values. ### Method `WithNewParameters(kv ...interface{}) ### Parameters - `kv` (...interface{}) - Key-value pairs for creating parameters. ``` -------------------------------- ### Initialize Allure Go Runner Source: https://github.com/ozontech/allure-go/blob/master/README.md Initializes a new Allure Go runner instance. This is the first step in setting up your test suite. ```go package test import ( t"testing" "github.com/ozontech/allure-go/pkg/framework/provider" "github.com/ozontech/allure-go/pkg/framework/runner" ) func TestRunner(t *testing.T) { r := runner.NewRunner(t, "My First Suite!") } ``` -------------------------------- ### Steps Methods Source: https://github.com/ozontech/allure-go/blob/master/pkg/framework/README.md Methods for logging and managing steps within Allure reports. ```APIDOC ## LogStep ### Description Works as `t.Log(args ...interface{})`, but also creates an `allure.Step` in the report. ### Method `LogStep(args ...interface{}) ### Parameters * `args` (...interface{}) - Variable number of arguments to log. ### Code Example ```go // Assuming 't' is an instance of AllureSteps or a compatible interface t.LogStep("This is a log message", 123) ``` ``` ```APIDOC ## LogfStep ### Description Works as `t.Logf(format string, args ...interface{})` but also creates an `allure.Step` in the report. ### Method `LogfStep(format string, args ...interface{}) ### Parameters * `format` (string) - The format string for the log message. * `args` (...interface{}) - Variable number of arguments to format into the log message. ### Code Example ```go // Assuming 't' is an instance of AllureSteps or a compatible interface t.LogfStep("Processing item %d", 42) ``` ``` ```APIDOC ## Step ### Description Adds a pre-created `allure.Step` object to the result. ### Method `Step(step *allure.Step) ### Parameters * `step` (*allure.Step) - The `allure.Step` object to add. ### Code Example ```go // Assuming 't' is an instance of AllureSteps or a compatible interface myStep := allure.NewStep("Custom Step", allure.Parameter{Name: "Key", Value: "Value"}) t.Step(myStep) ``` ``` ```APIDOC ## NewStep ### Description Creates a new `allure.Step` object and adds it to the result. ### Method `NewStep(stepName string, params ...allure.Parameter) ### Parameters * `stepName` (string) - The name of the new step. * `params` (...allure.Parameter) - Optional parameters for the step. ### Code Example ```go // Assuming 't' is an instance of AllureSteps or a compatible interface t.NewStep("Initialization", allure.Parameter{Name: "Config", Value: "Default"}) ``` ``` ```APIDOC ## WithNewStep ### Description Creates a new `allure.Step` object and runs an anonymous function within its context. The `StepCtx` interface allows interaction with the step during its execution. ### Method `WithNewStep(stepName string, step func(sCtx StepCtx), params ...allure.Parameter) ### Parameters * `stepName` (string) - The name of the new step. * `step` (func(sCtx StepCtx)) - An anonymous function to execute within the step's context. * `params` (...allure.Parameter) - Optional parameters for the step. ### Code Example ```go // Assuming 't' is an instance of AllureSteps or a compatible interface t.WithNewStep("Data Processing", func(sCtx StepCtx) { sctx.Log("Starting data processing...") // ... perform operations ... ssctx.Log("Data processing complete.") }) ``` ``` ```APIDOC ## WithNewAsyncStep ### Description Similar to `WithNewStep`, but executes the anonymous function asynchronously. ### Method `WithNewAsyncStep(stepName string, step func(sCtx StepCtx), params ...allure.Parameter) ### Parameters * `stepName` (string) - The name of the new step. * `step` (func(sCtx StepCtx)) - An anonymous function to execute within the step's context. * `params` (...allure.Parameter) - Optional parameters for the step. ### Code Example ```go // Assuming 't' is an instance of AllureSteps or a compatible interface t.WithNewAsyncStep("Background Task", func(sCtx StepCtx) { // ... perform async operations ... }) ``` ``` -------------------------------- ### Steps Methods Source: https://github.com/ozontech/allure-go/blob/master/pkg/framework/README.md Methods for logging and managing steps within Allure reports. ```APIDOC ## LogStep ### Description Logs arguments to the test output and creates an Allure step. ### Method `LogStep(args ...interface{}) ### Parameters - `args` (...interface{}) - The arguments to log. ## LogfStep ### Description Logs formatted arguments to the test output and creates an Allure step. ### Method `LogfStep(format string, args ...interface{}) ### Parameters - `format` (string) - The format string. - `args` (...interface{}) - The arguments to format and log. ## Step ### Description Adds a pre-created Allure step as a substep. ### Method `Step(step *allure.Step) ### Parameters - `step` (*allure.Step) - The Allure step to add. ## NewStep ### Description Creates a new Allure step object and adds it as a substep. ### Method `NewStep(stepName string, parameters ...allure.Parameter) ### Parameters - `stepName` (string) - The name of the new step. - `parameters` (...allure.Parameter) - Optional parameters for the step. ## WithNewStep ### Description Creates a new Allure step object and executes an anonymous function within its context. The `StepCtx` interface allows interaction with the step during execution. Adds the step as a substep. ### Method `WithNewStep(stepName string, step func(sCtx StepCtx), params ...allure.Parameter) ### Parameters - `stepName` (string) - The name of the new step. - `step` (func(sCtx StepCtx)) - The anonymous function to execute. - `params` (...allure.Parameter) - Optional parameters for the step. ## WithNewAsyncStep ### Description Similar to `WithNewStep`, but executes the anonymous function as an asynchronous process. ### Method `WithNewAsyncStep(stepName string, step func(sCtx StepCtx), params ...allure.Parameter) ### Parameters - `stepName` (string) - The name of the new step. - `step` (func(sCtx StepCtx)) - The anonymous function to execute asynchronously. - `params` (...allure.Parameter) - Optional parameters for the step. ## CurrentStep ### Description Returns a pointer to the current Allure step object. ### Method `CurrentStep() *allure.Step ### Returns - `*allure.Step` - A pointer to the current step. ``` -------------------------------- ### Create Nested Steps in Go Test Source: https://github.com/ozontech/allure-go/blob/master/README.md Illustrates how to create nested steps within a test case. Use `t.WithNewStep` to define parent steps and `ctx.NewStep` to create child steps, preserving the call order in the Allure report. ```go package examples import ( "github.com/ozontech/allure-go/pkg/framework/provider" "github.com/ozontech/allure-go/pkg/framework/suite" ) type StepTreeDemoSuite struct { suite.Suite } func (s *StepTreeDemoSuite) TestInnerSteps(t provider.T) { t.Epic("Demo") t.Feature("Inner Steps") t.Title("Simple Nesting") t.Description(` Step A is parent step for Step B and Step C Call order will be saved in allure report A -> (B, C)`) t.Tags("Steps", "Nesting") t.WithNewStep("Step A", func(ctx provider.StepCtx) { ctx.NewStep("Step B") ctx.NewStep("Step C") }) } ``` -------------------------------- ### Parametrized Tests in Allure Go Source: https://github.com/ozontech/allure-go/blob/master/README.md Illustrates how to create parametrized tests using the `TableTest` pattern. This allows running the same test logic with different input data, generated dynamically in `BeforeAll`. ```go package suite_demo import ( "testing" "github.com/jackc/fake" "github.com/ozontech/allure-go/pkg/framework/provider" "github.com/ozontech/allure-go/pkg/framework/suite" ) type ParametrizedSuite struct { suite.Suite ParamCities []string } func (s *ParametrizedSuite) BeforeAll(t provider.T) { for i := 0; i < 10; i++ { s.ParamCities = append(s.ParamCities, fake.City()) } } func (s *ParametrizedSuite) TableTestCities(t provider.T, city string) { t.Parallel() t.Require().NotEmpty(city) } func TestNewParametrizedDemo(t *testing.T) { suite.RunSuite(t, new(ParametrizedSuite)) } ``` -------------------------------- ### Add Text and JSON Attachments in Go Test Source: https://github.com/ozontech/allure-go/blob/master/README.md Shows how to add text and JSON attachments to test cases and steps. Use `t.Attachment` for test-level attachments and `step.Attachment` for step-level attachments, specifying the name, type, and content. ```go package examples import ( "encoding/json" "github.com/ozontech/allure-go/pkg/allure" "github.com/ozontech/allure-go/pkg/framework/provider" "github.com/ozontech/allure-go/pkg/framework/suite" ) type JSONStruct struct { Message string `json:"message"` } type AttachmentTestDemoSuite struct { suite.Suite } func (s *AttachmentTestDemoSuite) TestAttachment(t provider.T) { t.Epic("Demo") t.Feature("Attachments") t.Title("Test Attachments") t.Description(` Test's test body and all steps inside can contain attachments`) t.Tags("Attachments", "BeforeAfter", "Steps") attachmentText := `THIS IS A TEXT ATTACHMENT` t.Attachment(allure.NewAttachment("Text Attachment if TestAttachment", allure.Text, []byte(attachmentText))) step := allure.NewSimpleStep("Step A") var ExampleJson = JSONStruct{"this is JSON message"} attachmentJSON, _ := json.Marshal(ExampleJson) step.Attachment(allure.NewAttachment("Json Attachment for Step A", allure.JSON, attachmentJSON)) t.Step(step) } ``` -------------------------------- ### Step Constructors Source: https://github.com/ozontech/allure-go/blob/master/pkg/allure/README.md Provides constructors for creating new Step objects with various initial configurations. ```APIDOC ## NewStep ### Description Returns pointer to the new `allure.Step` object. ### Signature `NewStep(name string, status Status, start int64, stop int64, parameters []Parameter) *Step` ``` ```APIDOC ## NewSimpleStep ### Description Same as `NewStep` but the most of fields are pre populated. ### Signature `NewSimpleStep(name string, parameters ...Parameter) *Step` ``` -------------------------------- ### Extend Test Suite with Test Methods Source: https://github.com/ozontech/allure-go/blob/master/README.md This Go code shows how to add test methods to a previously defined test suite. Each method represents a test case and uses `provider.T` for Allure reporting. ```go package tests import ( "github.com/ozontech/allure-go/pkg/framework/provider" "github.com/ozontech/allure-go/pkg/framework/suite" ) type MyFirstSuite struct { suite.Suite } func (s *MyFirstSuite) TestMyFirstTest(t provider.T) { t.NewStep("My First Step!") } func (s *MyFirstSuite) TestMySecondTest(t provider.T) { t.WithNewStep("My Second Step!", func(sCtx provider.StepCtx) { sCtx.NewStep("My First SubStep!") }) } ``` -------------------------------- ### Result Framework, Language, Thread, and Package Labels Source: https://github.com/ozontech/allure-go/blob/master/pkg/allure/README.md Methods for setting framework, language, thread, and package labels on an Allure Result. ```APIDOC ## WithFrameWork ### Description Sets the `Framework` label for the `allure.Result`. Returns a pointer to the `Result` for chaining. ### Signature `WithFrameWork(framework string) *Result` ## WithLanguage ### Description Sets the `Language` label for the `allure.Result`. Returns a pointer to the `Result` for chaining. ### Signature `WithLanguage(language string) *Result` ## WithThread ### Description Sets the `Thread` label for the `allure.Result`. Returns a pointer to the `Result` for chaining. ### Signature `WithThread(thread string) *Result` ## WithPackage ### Description Sets the `Package` label for the `allure.Result`. Returns a pointer to the `Result` for chaining. ### Signature `WithPackage(pkg string) *Result` ``` -------------------------------- ### Warning on Async Steps with Require Asserts Source: https://github.com/ozontech/allure-go/blob/master/pkg/framework/README.md Using require asserts with asynchronous steps is not recommended due to the behavior of `testing.T.FailNow()`, which can lead to data loss or incomplete steps. ```go // NOTE: USING REQUIRE ASSERTS WITH ASYNC STEPS ARE NOT RECOMMENDED. Reason: `testing.T.FailNow()` // makes `go.Exit()` and It's impossible to handle this situation, so you can lose your step or test data. ``` -------------------------------- ### Go: Initialize Allure Test Parameters Source: https://github.com/ozontech/allure-go/blob/master/README.md Use `InitializeTestsParams` to set up parameters for parametrized tests, assigning unique Allure IDs and titles to each test case. This method is called before tests are run. ```go package suite_demo import ( "testing" "github.com/jackc/fake" "github.com/ozontech/allure-go/pkg/framework/provider" "github.com/ozontech/allure-go/pkg/framework/suite" ) type CitiesParam struct { allureID string title string value string } func (p CitiesParam) GetAllureID() string { return p.allureID } func (p CitiesParam) GetAllureTitle() string { return p.title } type ParametrizedSuite struct { suite.Suite ParamCities []CitiesParam } func (s *ParametrizedSuite) InitializeTestsParams() { s.ParamCities = make([]CitiesParam, 2) s.ParamCities[0] = CitiesParam{ title: "Title for city test #1", allureID: "101", value: fake.City(), } s.ParamCities[1] = CitiesParam{ title: "Title for city test #2", allureID: "102", value: fake.City(), } } func (s *ParametrizedSuite) BeforeAll(t provider.T) { // setup suit here } func (s *ParametrizedSuite) TableTestCities(t provider.T, city CitiesParam) { t.Parallel() t.Require().NotEmpty(city.value) } func TestNewParametrizedDemo(t *testing.T) { suite.RunSuite(t, new(ParametrizedSuite)) } ``` -------------------------------- ### Allure Go Assertion Methods Source: https://github.com/ozontech/allure-go/blob/master/pkg/framework/README.md Lists various assertion methods available for use with the ProviderT interface. These methods cover a wide range of checks including equality, error handling, nil checks, length, content, and type comparisons. ```go Same(t ProviderT, expected interface{}, actual interface{}, msgAndArgs ...interface{}) ``` ```go NotSame(t ProviderT, expected interface{}, actual interface{}, msgAndArgs ...interface{}) ``` ```go Equal(t ProviderT, expected interface{}, actual interface{}, msgAndArgs ...interface{}) ``` ```go NotEqual(t ProviderT, expected interface{}, actual interface{}, msgAndArgs ...interface{}) ``` ```go EqualValues(t ProviderT, expected interface{}, actual interface{}, msgAndArgs ...interface{}) ``` ```go NotEqualValues(t ProviderT, expected interface{}, actual interface{}, msgAndArgs ...interface{}) ``` ```go Error(t ProviderT, err error, msgAndArgs ...interface{}) ``` ```go NoError(t ProviderT, err error, msgAndArgs ...interface{}) ``` ```go EqualError(t ProviderT, theError error, errString string, msgAndArgs ...interface{}) ``` ```go ErrorIs(t ProviderT, err error, target error, msgAndArgs ...interface{}) ``` ```go ErrorAs(t ProviderT, err error, target interface{}, msgAndArgs ...interface{}) ``` ```go NotNil(t ProviderT, object interface{}, msgAndArgs ...interface{}) ``` ```go Nil(t ProviderT, object interface{}, msgAndArgs ...interface{}) ``` ```go Len(t ProviderT, object interface{}, length int, msgAndArgs ...interface{}) ``` ```go NotContains(t ProviderT, s interface{}, contains interface{}, msgAndArgs ...interface{}) ``` ```go Contains(t ProviderT, s interface{}, contains interface{}, msgAndArgs ...interface{}) ``` ```go Greater(t ProviderT, e1 interface{}, e2 interface{}, msgAndArgs ...interface{}) ``` ```go GreaterOrEqual(t ProviderT, e1 interface{}, e2 interface{}, msgAndArgs ...interface{}) ``` ```go Less(t ProviderT, e1 interface{}, e2 interface{}, msgAndArgs ...interface{}) ``` ```go LessOrEqual(t ProviderT, e1 interface{}, e2 interface{}, msgAndArgs ...interface{}) ``` ```go Implements(t ProviderT, interfaceObject interface{}, object interface{}, msgAndArgs ...interface{}) ``` ```go Empty(t ProviderT, object interface{}, msgAndArgs ...interface{}) ``` ```go NotEmpty(t ProviderT, object interface{}, msgAndArgs ...interface{}) ``` ```go WithinDuration(t ProviderT, expected, actual time.Time, delta time.Duration, msgAndArgs ...interface{}) ``` ```go JSONEq(t ProviderT, expected, actual string, msgAndArgs ...interface{}) ``` ```go JSONContains(t ProviderT, expected, actual string, msgAndArgs ...interface{}) ``` ```go Subset(t ProviderT, list, subset interface{}, msgAndArgs ...interface{}) ``` ```go IsType(t ProviderT, expectedType interface{}, object interface{}, msgAndArgs ...interface{}) ``` ```go True(t ProviderT, value bool, msgAndArgs ...interface{}) ``` ```go False(t ProviderT, value bool, msgAndArgs ...interface{}) ``` ```go Regexp(t ProviderT, rx interface{}, str interface{}, msgAndArgs ...interface{}) ``` ```go ElementsMatch(ProviderT, listA interface{}, listB interface{}, msgAndArgs ...interface{}) ``` ```go DirExists(t ProviderT, path string, msgAndArgs ...interface{}) ``` ```go Condition(t ProviderT, condition assert.Comparison, msgAndArgs ...interface{}) ``` ```go Zero(t ProviderT, i interface{}, msgAndArgs ...interface{}) ``` ```go NotZero(t ProviderT, i interface{}, msgAndArgs ...interface{}) ``` -------------------------------- ### Container Constructors Source: https://github.com/ozontech/allure-go/blob/master/pkg/allure/README.md Functions for creating new Allure Container objects. ```APIDOC ## NewContainer ### Description Returns pointer to the new `allure.Container` object. ### Signature `NewContainer() *Container` ``` -------------------------------- ### Attachments Methods Source: https://github.com/ozontech/allure-go/blob/master/pkg/framework/README.md Methods for adding attachments to the current step. ```APIDOC ## WithAttachments ### Description Adds `allure.Attachment` objects to the current step. ### Method `WithAttachments(attachment ...*allure.Attachment) ### Parameters - `attachment` (...*allure.Attachment) - The attachments to add. ## WithNewAttachment ### Description Creates a new `allure.Attachment` with the given name, MIME type, and content, and adds it to the current step. ### Method `WithNewAttachment(name string, mimeType allure.MimeType, content []byte) ### Parameters - `name` (string) - The name of the attachment. - `mimeType` (allure.MimeType) - The MIME type of the attachment. - `content` ([]byte) - The content of the attachment. ``` -------------------------------- ### Parameter Constructors Source: https://github.com/ozontech/allure-go/blob/master/pkg/allure/README.md Constructors for creating parameters to add additional information to test steps. ```APIDOC ## Parameter Constructors ### `NewParameter(name string, value ...interface{}) Parameter` **Description**: Builds new `Parameter` object. Value **must** be able to cast to string. ### `NewParameters(kv ...interface{}) []Parameter` **Description**: Returns list of `allure.Parameter` objects. Each even string is considered a parameter name, and each odd-value of the parameter. ``` -------------------------------- ### Container Methods Source: https://github.com/ozontech/allure-go/blob/master/pkg/allure/README.md Methods available for Allure Container objects. ```APIDOC ## GetUUID ### Description Returns container's UUID. ### Signature `GetUUID() string` ``` ```APIDOC ## AddChild ### Description Adds passed UUID as child. ### Signature `AddChild(childUUID uuid.UUID)` ``` ```APIDOC ## IsEmpty ### Description Returns `true` if arrays `Container.Befores` and `Container.Afters` are empty. ### Signature `IsEmpty() bool` ``` ```APIDOC ## Print ### Description Creates `xxxxxx-container.json` file and calls `PrintAttachments` if any step exists in `Container.Befores` and `Container.Afters`. ### Signature `Print() error` ``` ```APIDOC ## ToJSON ### Description Marshall `allure.Container` to the JSON. Returns error if has any. ### Signature `ToJSON() ([]byte, error)` ``` ```APIDOC ## PrintAttachments ### Description It goes through all `Container.Befores` and `Container.Afters` of the Container and calls the `Container.PrintAttachments()` method at each `allure.Step`. ### Signature `PrintAttachments()` ``` ```APIDOC ## Begin ### Description Sets `Container.Start` = `allure.GetNow()`. ### Signature `Begin()` ``` ```APIDOC ## Finish ### Description Sets `Container.Stop` = `allure.GetNow()`. ### Signature `Finish()` ``` ```APIDOC ## Done ### Description Calls `Finish()` and `Print()` methods. Returns error if has any. ### Signature `Done() error` ``` -------------------------------- ### Define a Test Suite Structure Source: https://github.com/ozontech/allure-go/blob/master/README.md This Go code defines the basic structure of a test suite using the Allure Go framework. It involves creating a struct that embeds `suite.Suite`. ```go package tests import ( "github.com/ozontech/allure-go/pkg/framework/suite" ) type MyFirstSuite struct { suite.Suite } ``` -------------------------------- ### ProviderT Interface Definition Source: https://github.com/ozontech/allure-go/blob/master/pkg/framework/README.md Defines the interface for test providers, including methods for reporting steps, errors, and failing tests. This interface is implemented by the testing framework to enable assertion capabilities. ```go package asserts type ProviderT interface { Step(step *allure.Step) Errorf(format string, args ...interface{}) FailNow() } ``` -------------------------------- ### Extend Runner with Tests and Steps Source: https://github.com/ozontech/allure-go/blob/master/README.md Adds new tests and steps to the Allure Go runner. Supports nested steps for detailed reporting. ```go package test import ( t"testing" "github.com/ozontech/allure-go/pkg/framework/provider" "github.com/ozontech/allure-go/pkg/framework/runner" ) func TestRunner(t *testing.T) { r := runner.NewRunner(t, "My First Suite!") r.NewTest("My first test", func(t provider.T) { t.NewStep("My First Step!") }) r.NewTest("My second test", func(t provider.T) { t.WithNewStep("My Second Step!", func(sCtx provider.StepCtx) { sCtx.NewStep("My First SubStep!") }) }) } ``` -------------------------------- ### provider.T Extended Methods Source: https://github.com/ozontech/allure-go/blob/master/pkg/framework/README.md The provider.T interface extends the standard Go testing.TB interface and provides additional methods for test control and reporting within Allure. ```APIDOC ## provider.T Extended Methods ### Description These methods extend the standard `testing.TB` interface, offering Allure-specific functionalities for test reporting and control. ### Methods - **`Name()`**: Returns `result.Name`. - **`Fail()`**: Fails the current test, marking it as `Failed`. This method **DOES NOT STOP** test execution. - **`FailNow()`**: Fails the current test, marking it as `Failed`. This method **STOPS** test execution immediately. - **`Error(args ...interface{})` / `Errorf(format string, args ...interface{})`**: Fails the test, sets the status to `Failed`, and adds an error message to `result.StatusDetails`. These methods **DO NOT STOP** test execution. - **`Fatal(args ...interface{})` / `Fatalf(format string, args ...interface{})`**: Fails the test, sets the status to `Failed`, and adds an error message to `result.StatusDetails`. These methods **STOP** test execution immediately. - **`Skip(args ...interface{})` / `Skipf(format string, args ...interface{})`**: Skips the current test and adds a skip message to `result.Status`. These methods **STOP** test execution. ``` -------------------------------- ### Result Suite and Host Labels Source: https://github.com/ozontech/allure-go/blob/master/pkg/allure/README.md Methods for setting specific suite, sub-suite, and host labels on an Allure Result. ```APIDOC ## WithParentSuite ### Description Sets the `ParentSuite` label for the `allure.Result`. Returns a pointer to the `Result` for chaining. ### Signature `WithParentSuite(parentName string) *Result` ## WithSuite ### Description Sets the `Suite` label for the `allure.Result`. Returns a pointer to the `Result` for chaining. ### Signature `WithSuite(suiteName string) *Result` ## WithHost ### Description Sets the `Host` label for the `allure.Result`. Returns a pointer to the `Result` for chaining. ### Signature `WithHost(hostName string) *Result` ## WithSubSuites ### Description Sets all `SubSuite` labels for the `allure.Result`. Accepts a variable number of suite names. Returns a pointer to the `Result` for chaining. ### Signature `WithSubSuites(children ...string) *Result` ``` -------------------------------- ### Configure Allure Issue Pattern Source: https://github.com/ozontech/allure-go/blob/master/README.md Sets the environment variable ALLURE_ISSUE_PATTERN to define a URL pattern for issues. This is mandatory for linking issues correctly. The pattern must contain '%s'. ```go package provider_demo import ( "testing" "github.com/ozontech/allure-go/pkg/framework/provider" "github.com/ozontech/allure-go/pkg/framework/runner" ) func TestSampleDemo(t *testing.T) { runner.Run(t, "Just Link", func(t provider.T) { t.SetIssue("https://pkg.go.dev/github.com/stretchr/testify") }) runner.Run(t, "With Pattern", func(t provider.T) { _ = os.Setenv("ALLURE_ISSUE_PATTERN", "https://pkg.go.dev/github.com/stretchr/%s") t.SetIssue("testify") }) } ``` -------------------------------- ### Link Constructors Source: https://github.com/ozontech/allure-go/blob/master/pkg/allure/README.md Constructors for creating different types of links to external resources or test cases. ```APIDOC ## Link Constructors ### `NewLink(name string, _type LinkTypes, url string) Link` **Description**: Base constructor. Returns new `allure.Link`. ### `TestCaseLink(testCase string) Link` **Description**: Returns `TESTCASE` type link. It uses environment variable `ALLURE_TESTCASE_PATTERN` as pattern. ### `IssueLink(issue string) Link` **Description**: Returns `ISSUE` type link. It uses environment variable `ALLURE_ISSUE_PATTERN` as pattern. ### `LinkLink(linkname, link string) Link` **Description**: Returns `LINK` type link. ``` -------------------------------- ### Attachment Constructors Source: https://github.com/ozontech/allure-go/blob/master/pkg/allure/README.md Functions for creating new Allure Attachment objects. ```APIDOC ## NewAttachment ### Description Returns pointer to the new `allure.Attachment` object. ### Signature `NewAttachment(name string, mimeType MimeType, content []byte) *Attachment` ``` -------------------------------- ### Configure Allure TestCase Pattern Source: https://github.com/ozontech/allure-go/blob/master/README.md Sets the environment variable ALLURE_TESTCASE_PATTERN to define a URL pattern for test cases. This is mandatory for linking test cases correctly. The pattern must contain '%s'. ```go package provider_demo import ( "testing" "github.com/ozontech/allure-go/pkg/framework/provider" "github.com/ozontech/allure-go/pkg/framework/runner" ) func TestSampleDemo(t *testing.T) { runner.Run(t, "Just Link", func(t provider.T) { t.SetTestCase("https://pkg.go.dev/github.com/stretchr/testify") }) runner.Run(t, "With Pattern", func(t provider.T) { _ = os.Setenv("ALLURE_TESTCASE_PATTERN", "https://pkg.go.dev/github.com/stretchr/%s") t.SetTestCase("testify") }) } ``` -------------------------------- ### Description Label Methods Source: https://github.com/ozontech/allure-go/blob/master/pkg/framework/README.md Methods for adding and managing Allure labels to test results. ```APIDOC ## Description Label Methods (`DescriptionLabels` interface) ### Description Methods for adding and managing Allure labels to test results. ### Methods - `ID(value string)`: Adds `id` allure label. - `AllureID(value string)`: Adds `ALLURE_ID` allure label. - `Epic(value string)`: Adds `epic` allure label. - `Feature(value string)`: Adds `feature` allure label. - `Story(value string)`: Adds `story` allure label. - `Severity(severityType allure.SeverityType)`: Adds `severity` allure label. - `Tag(value string)`: Adds `tag` allure label. - `Tags(values ...string)`: Adds multiple `tag` allure labels. - `Owner(value string)`: Adds `owner` allure label. - `Lead(value string)`: Adds `lead` allure label. - `Label(label allure.Label)`: Adds a custom allure label. - `Labels(labels ...allure.Label)`: Adds multiple custom allure labels. - `ReplaceLabel(label allure.Label)`: Replaces an existing label with the provided one if they share the same name. **Note**: Some labels like `language`, `host`, `framework` have default values and can only be modified using `ReplaceLabel`. ``` -------------------------------- ### provider.T Description Methods Source: https://github.com/ozontech/allure-go/blob/master/pkg/framework/README.md Methods for setting the title and description of a test case in the Allure report. ```APIDOC ## provider.T Description Methods ### Description These methods allow you to set the title and detailed description for a test case, which will be reflected in the Allure report. ### Methods - **`Title(args ...interface{})`**: Sets the `result.Name` field using `fmt.Sprint` to format the provided arguments. - **`Titlef(format string, args ...interface{})`**: Sets the `result.Name` field using `fmt.Sprintf` to format the provided arguments according to the format string. - **`Description(args ...interface{})`**: Sets the `result.Description` field using `fmt.Sprint` to format the provided arguments. - **`Descriptionf(format string, args ...interface{})`**: Sets the `result.Description` field using `fmt.Sprintf` to format the provided arguments according to the format string. ```