-
Notifications
You must be signed in to change notification settings - Fork 0
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
base: main
Are you sure you want to change the base?
My n unit #6
Conversation
|
||
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}}")] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Отключение предупреждений StyleCop само генерирует кучу предупреждений StyleCop, иронично
MyNUnit/MyNUnit/MyAssert.cs
Outdated
/// <summary> | ||
/// Class for asserting. | ||
/// </summary> | ||
public static class MyAssert |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Библиотеку Assert-ов не заказывали, но пусть будет
MyNUnit/MyNUnit/MyAssert.cs
Outdated
/// <summary> | ||
/// Class for assertion exception. | ||
/// </summary> | ||
public class AssertionException : Exception |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
По традиции каждый класс в своём файле, даже если это несчастное исключение
MyNUnit/MyNUnit/Program.cs
Outdated
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) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Не используйте явный Main, мы не в 2020-м :)
MyNUnit/MyNUnit/Program.cs
Outdated
{ | ||
if (args.Length != 1) | ||
{ | ||
Console.WriteLine($"Invalid input."); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Крайне огорчают утилиты, которые на неправильные параметры говорят, что они неправильные, но не говорят, как надо. Потом будете в продакшн делать сообщения об ошибке как в сервисах Яндекса, "Уважаемый, вы что, не видите, у нас обед!" :)
MyNUnit/MyNUnit/Tester.cs
Outdated
|
||
if (result is Task taskResult) | ||
{ | ||
await taskResult; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Асинхронные тесты тоже не заказывали, но ок :)
MyNUnit/MyNUnit/Tester.cs
Outdated
throw; | ||
} | ||
|
||
results.Add(new MyTestResult(method.Name, "Passed", string.Empty)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Если исключение ожидалось, но его не было, тест типа пройдёт
MyNUnit/MyNUnit/Tester.cs
Outdated
/// <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) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Это, скорее всего, record. И тоже в отдельный файл его
MyNUnit/MyNUnit/Tester.cs
Outdated
private static void RunBefore(object instance) | ||
{ | ||
var beforeMethods = instance.GetType().GetMethods() | ||
.Where(m => m.GetCustomAttributes(typeof(BeforeAttribute), false).Length != 0); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Тут и везде стоит добавить базовую проверку корректности тестовых методов — например, что у них нет параметров и возвращаемого значения, что они static/не static в зависимости от типа своего атрибута и т.п. Чтобы помочь пользователю отладить тесты.
MyNUnit/MyNUnitTest/MyNUnitTests.cs
Outdated
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", "") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Отступов не хватает
No description provided.