-
Notifications
You must be signed in to change notification settings - Fork 34
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
[suggestion] NUnit1028 could be improved #714
Comments
@Bartleby2718 Yes, the wording could be improved, to something like |
I am confused about this. Is it a good choice to make them internal?? NUnit1028 is complaining about them if internal ALSO. |
No. A test should be self-contained not expose methods to be called from elsewhere. Depending on what those methods do they could interfere with a test in progress and affect the result. If a method is shared between tests then they should be moved to a separate non-test class. |
I see... and then how should those non-test classes be annotated? [SetUpFixture]
public partial class Testing
{
private static ITestDatabase s_database;
private static CustomWebApplicationFactory s_factory = null!;
private static IServiceScopeFactory s_scopeFactory = null!;
private static string? s_userId;
[OneTimeSetUp]
public async Task RunBeforeAnyTests()
{
s_database = await TestDatabaseFactory.CreateAsync();
s_factory = new CustomWebApplicationFactory(s_database.GetConnection());
s_scopeFactory = s_factory.Services.GetRequiredService<IServiceScopeFactory>();
}
internal static async Task<TResponse> SendAsync<TResponse>(IRequest<TResponse> request)
{
using var scope = s_scopeFactory.CreateScope();
var mediator = scope.ServiceProvider.GetRequiredService<ISender>();
return await mediator.Send(request);
} |
For your case, I would removal all attributes from your class and create a new SetUpFixture class which calls Your test code can then keep calling |
Problem 1:
nunit.analyzers/src/nunit.analyzers/NonTestMethodAccessibilityLevel/NonTestMethodAccessibilityLevelAnalyzer.cs
Lines 63 to 75 in e52e3a1
clearly says that NUnit1028 detects public or internal methods, but the title, message, and description don't mention
internal
:nunit.analyzers/src/nunit.analyzers/NonTestMethodAccessibilityLevel/NonTestMethodAccessibilityLevelConstants.cs
Lines 5 to 7 in e52e3a1
Problem 2:
nunit.analyzers/src/nunit.analyzers/NonTestMethodAccessibilityLevel/NonTestMethodAccessibilityLevelCodeFix.cs
Lines 61 to 101 in e52e3a1
private
, but it should suggest so only if it isn't used anywhere else. Not sure if this can be done, but it should definitely be possible to reduce false positives.The text was updated successfully, but these errors were encountered: