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

My n unit #6

Open
wants to merge 14 commits into
base: main
Choose a base branch
from
Open

My n unit #6

wants to merge 14 commits into from

Conversation

IliaSotnikov2005
Copy link
Owner

No description provided.


using System.Diagnostics.CodeAnalysis;

[assembly: SuppressMessage("StyleCop.CSharp.SpacingRules", "SA1010:Opening square brackets should be spaced correctly", Justification = "<Pending>", Scope = "member", Target = "~M:MyNUnit.Tester.RunTestClass(System.Type)~System.Threading.Tasks.Task{System.Collections.Generic.List{MyNUnit.MyTestResult}}")]

Choose a reason for hiding this comment

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

Отключение предупреждений StyleCop само генерирует кучу предупреждений StyleCop, иронично

/// <summary>
/// Class for asserting.
/// </summary>
public static class MyAssert

Choose a reason for hiding this comment

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

Библиотеку Assert-ов не заказывали, но пусть будет

/// <summary>
/// Class for assertion exception.
/// </summary>
public class AssertionException : Exception

Choose a reason for hiding this comment

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

По традиции каждый класс в своём файле, даже если это несчастное исключение

Comment on lines 10 to 17
public class Program
{
/// <summary>
/// Main method.
/// </summary>
/// <param name="args">Arguments for application.</param>
/// <returns>Task.</placeholder></returns>
public static async Task Main(string[] args)

Choose a reason for hiding this comment

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

Не используйте явный Main, мы не в 2020-м :)

{
if (args.Length != 1)
{
Console.WriteLine($"Invalid input.");

Choose a reason for hiding this comment

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

Крайне огорчают утилиты, которые на неправильные параметры говорят, что они неправильные, но не говорят, как надо. Потом будете в продакшн делать сообщения об ошибке как в сервисах Яндекса, "Уважаемый, вы что, не видите, у нас обед!" :)


if (result is Task taskResult)
{
await taskResult;

Choose a reason for hiding this comment

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

Асинхронные тесты тоже не заказывали, но ок :)

throw;
}

results.Add(new MyTestResult(method.Name, "Passed", string.Empty));

Choose a reason for hiding this comment

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

Если исключение ожидалось, но его не было, тест типа пройдёт

/// <param name="name">Name of the test.</param>
/// <param name="status">Status of the test.</param>
/// <param name="message">Message of the test.</param>
public class MyTestResult(string name, string status, string message)

Choose a reason for hiding this comment

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

Это, скорее всего, record. И тоже в отдельный файл его

private static void RunBefore(object instance)
{
var beforeMethods = instance.GetType().GetMethods()
.Where(m => m.GetCustomAttributes(typeof(BeforeAttribute), false).Length != 0);

Choose a reason for hiding this comment

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

Тут и везде стоит добавить базовую проверку корректности тестовых методов — например, что у них нет параметров и возвращаемого значения, что они static/не static в зависимости от типа своего атрибута и т.п. Чтобы помочь пользователю отладить тесты.

Comment on lines 15 to 18
new ("Test_ShouldBePassed", "Passed", ""),
new ("Test_ShouldBeIgnored", "Ignored", "ignore"),
new ("Test_ShouldBeFailed", "Failed", "Exception has been thrown by the target of an invocation."),
new ("Test_ShouldThrowException", "Passed", "")

Choose a reason for hiding this comment

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

Отступов не хватает

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