Skip to content

HW5 MyNUnit#8

Open
khusainovilas wants to merge 1 commit intomainfrom
task5-mynunit
Open

HW5 MyNUnit#8
khusainovilas wants to merge 1 commit intomainfrom
task5-mynunit

Conversation

@khusainovilas
Copy link
Owner

No description provided.

if (result != 5)
{
throw new InvalidOperationException($"Expected 5, but got {result}");
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Если уж Вы заморочились и написали настоящие тесты, то можно было дополнительно заморочиться и написать свой Assert.

public void Calculator_Divide_ByZero_ShouldThrow()
{
Calculator.Divide(10, 0);
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

И можно более активно использовать =>

</ItemGroup>

<ItemGroup>
<PackageReference Include="StyleCop.Analyzers" Version="1.1.118">

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

StyleCop староват, надо 1.2-beta. Иначе он нового C# не знает

Assert.That(testResult.Exception, Is.Not.Null);
});
}
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Надо ещё проверить на ситуацию, когда исключение ожидалось, но не брошено, на то, что вызываются Before/After и т.д., и на исключения в них.

/// Gets the reason why the test is ignored.
/// </summary>
public string Reason { get; }
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ignore просили просто как строковое свойство у атрибута Test, но окей, так тоже сойдёт, можно не править

/// Gets exception thrown by test.
/// </summary>
public Exception? Exception { get; init; }
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Тут лучше бы подошёл record с позиционными свойствами. То же самое, но в разы короче писать.

/// <summary>
/// Test failed.
/// </summary>
Failed,

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Лучше различать Failed (не прошёл сам тест) и Errored (не прошёл один из вспомогательных методов, типа BeforeClass, так что с самим тестом, может, всё и ок).

/// Test was ignored.
/// </summary>
Ignored,
} No newline at end of file

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

И опять-таки, правильнее держать каждый тип в своём файле. Так проще ориентироваться в проекте.

{
InvokeStatic(beforeClass);

foreach (var test in tests)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Так получается, что если усть одна сборка с одним классом и тысячей тестов в нём, ничего не выполняется параллельно.

}
finally
{
InvokeStatic(afterClass);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

afterClass тоже может бросить исключение, и в этом случае все тесты в классе тоже надо пометить как Errored, даже если они прошли.

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

Successfully merging this pull request may close these issues.

2 participants