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

Странная работа метода t.WithNewStep, t.Step #4

Closed
anton-ryabkov opened this issue May 24, 2022 · 3 comments
Closed
Assignees
Labels
good first issue Good for newcomers question Further information is requested

Comments

@anton-ryabkov
Copy link

anton-ryabkov commented May 24, 2022

Добрый день

Сегодня попробовал использовать ваш проект для написания unit тестов, в результате проб возник следующий вопрос: если я в тесте делаю Step (через WithNewStep) и в переданной функции тест фейлится (require не проходит), то в allure отчете все равно данный шаг помечается как успешный. Пример кода, и отчета прилагаю:

type SomeSuite struct {
	suite.Suite
}

func (s *SomeSuite) TestSome(t provider.T) {
	t.WithNewStep("Step 1", func(sCtx provider.StepCtx) {
		require.Equal(t, 2, 2)
	})
	t.WithNewStep("Шаг 2", func(sCtx provider.StepCtx) {
		require.Equal(t, 2, 3)
	})
	t.WithNewStep("Шаг 3", func(sCtx provider.StepCtx) {
		require.Equal(t, 2, 2)
	})

}

func TestSkipDemo(t *testing.T) {
	suite.RunSuite(t, new(SomeSuite))
}

Аналогично если делать t.Step.

133a9d3f-db0d-11ec-9001-bce92f7d8cfc-result.zip

Подскажите, это ожидаемое поведение, или же нет?

@koodeex
Copy link
Collaborator

koodeex commented May 25, 2022

это ожидаемое, да

в интерфейсе StepCtx есть методы Require() и Assert() для отображения состояния шагов рекомендуется использование ассертов оттуда (эти ассерты так же будут отображены в отчете)

type SomeSuite struct {
	suite.Suite
}

func (s *SomeSuite) TestSome(t provider.T) {
	t.WithNewStep("Step 1", func(sCtx provider.StepCtx) {
		sCtx.Require().Equal(2, 2)
	})
	t.WithNewStep("Шаг 2", func(sCtx provider.StepCtx) {
		sCtx.Require().Equal(2, 3)
	})
	t.WithNewStep("Шаг 3", func(sCtx provider.StepCtx) {
		sCtx.Require().Equal(2, 2)
	})

}

func TestSkipDemo(t *testing.T) {
	suite.RunSuite(t, new(SomeSuite))
}

Альтернативно, Вы можете попробовать прокидывать вместо t в ассерты интерфейс provider.StepCtx

type SomeSuite struct {
	suite.Suite
}

func (s *SomeSuite) TestSome(t provider.T) {
	t.WithNewStep("Step 1", func(sCtx provider.StepCtx) {
		require.Equal(sCtx, 2, 2)
	})
	t.WithNewStep("Шаг 2", func(sCtx provider.StepCtx) {
		require.Equal(sCtx, 2, 2)
	})
	t.WithNewStep("Шаг 3", func(sCtx provider.StepCtx) {
		require.Equal(sCtx, 2, 2)
	})

}

func TestSkipDemo(t *testing.T) {
	suite.RunSuite(t, new(SomeSuite))
}

Это работает так, потому что в testify используется интерфейс TestingT, который реализует как provider.StepCtx, так и provider.T

@koodeex
Copy link
Collaborator

koodeex commented May 25, 2022

@anton-ryabkov . подскажите, смог ли я ответить на Ваш вопрос?

@koodeex koodeex self-assigned this May 25, 2022
@koodeex koodeex added good first issue Good for newcomers question Further information is requested labels May 25, 2022
@anton-ryabkov
Copy link
Author

Антон, добрый день.
Да, спасибо. Это то что надо.
Перевел тест на использование require.Equal(sCtx, 2, 3) и теперь отчет формируется правильно 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants