Skip to content

N unit - #25

Open
Palezehvat wants to merge 6 commits into
masterfrom
NUnit
Open

Palezehvat wants to merge 6 commits into
masterfrom
NUnit

Conversation

@Palezehvat

Copy link
Copy Markdown
Owner

No description provided.

@YuriUfimtsev YuriUfimtsev left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Пока много предупреждений компилятора и мало тестов. Ну и структуру надо бы в порядок привести

Comment thread MyNUnit/MyNUnit/Attributes.cs Outdated
namespace Attributes;

[AttributeUsage(AttributeTargets.Method, AllowMultiple = false)]
public class Test : Attribute

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Атрибуты надо по файлам разнести: один файл -- один класс. У каждого должен быть конструктор (даже пустой). И обязательно нужно их называть в виде ...Attribute. Здесь, например, TestAttribute

Comment thread MyNUnit/MyNUnit/Attributes.cs Outdated
public string? Ignored { get; set; }
}

[AttributeUsage(AttributeTargets.All)]

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Почему здесь All, а не Method? Все эти шесть атрибутов же для методов предназначены

Comment thread MyNUnit/MyNUnit/ApplicationForTests.cs Outdated
Ignored
}

public class ResultsTests

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Если этот класс необходим родительскому классу и не нужен внешнему миру, то надо его сделать private-вложенным. Если же нужно иметь возможность обращаться к его свойствам/методам, то надо его в отдельный файл вынести

Comment thread MyNUnit/MyNUnit/ApplicationForTests.cs Outdated
{
public string name { get; }

public long workTime { get; }

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

public => свойство => с большой буквы :)

@YuriUfimtsev

Copy link
Copy Markdown

Атрибуты теперь куда-то пропали


namespace MyNUnit;

public class ApplicationForTests

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Надо комментарии


using MyNUnit.Atributes;

namespace MyNUnit;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

namespace лучше первой строкой файла, сразу после шапки с лицензией


public class ApplicationForTests
{
public readonly List<ResultsTests> listOfResults = new();

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

public-всё в .NET именуется с заглавной. Но вообще, плохая идея делать мутабельный ссылочный тип readonly public-полем. Любой извне сможет взять и положить в список какой-то элемент — потому что readonly только ссылка, а не то, на что она указывает.

Parallel.ForEach(classes, StartTests);
}

private static MethodInfo[]? GetMethodsByAtributeAndClass(Type _class, Type atribute)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Attribute пишется с двумя t, прошу прощения за придирку :)

var methodsBefore = GetMethodsByAtributeAndClass(_class, typeof(BeforeAttribute));
var methodsAfter = GetMethodsByAtributeAndClass(_class, typeof(AfterAttribute));
var methods = _class.GetMethods();
foreach(var method in methods)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Suggested change
foreach(var method in methods)
foreach (var method in methods)

{
throw new NullReferenceException();
}
foreach(var method in methods)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Suggested change
foreach(var method in methods)
foreach (var method in methods)

}
}
}
catch(Exception ex)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Suggested change
catch(Exception ex)
catch (Exception ex)

var exceptionType = ex.GetType();

if (testAttribute != null && testAttribute.Expected != null && testAttribute.Expected.IsAssignableFrom(exceptionType) ||
(ex.InnerException != null && testAttribute != null && testAttribute.Expected != null && testAttribute.Expected.IsAssignableFrom(ex.InnerException.GetType())))

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Сложные условия стоит выносить в отдельный метод

[AttributeUsage(AttributeTargets.Method)]
public class AfterAttribute : Attribute
{
public AfterAttribute() { }

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Это не нужно, пустой конструктор сгенерируется сам, если в классе нет конструкторов

Comment on lines +9 to +13
[AfterAttribute]
public void Method()
{
;
}

Copy link
Copy Markdown

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.

4 participants