Implementation of Unit test and acceptance test in a .NET project

Thibaut

I've read this article and a couple of others about testing and I think I've understand the theory but not the implementation in a real .NET project.

My project is decomposed in multiple (functional) assemblies and I wish to test it. Most of my methods and properties are private or internal so I can't access them from my test assembly. I only test the public one (in order to test all the paths of my assembly).

I'm wondering about the test I'm doing because these tests aren't unit-test because I'm using other services like a database, or other services like Microsoft HPC... Am I right ? In my opinion, if I want to do some unit test, I have to test private methods and properties, thing that is controversial.

I'm using Nunit and I was wondering if I could put integration test AND unit test in the framework ?

Is there any .NET opensource project with unit test and acceptance test that I could check out ?

Thanks

Torbjörn Kalin

Many questions...

public/private: Typically, you only want to test through the public interface. If you want to test a private method it's probably a sign of that you should split the class into two and let the private methods become public (or internal). SRP. To test internal method, check this answer.

When writing a test you want to test the behaviour of the system. With behaviour, think of how the system behaves as seen from the end user (although there could be other interesting stakeholders as well). If you do this, you seldom encounter the problem with wanting to test private methods.

The difference between a unit test and an integration test is debated and, in my opinion, not a very important debate. What's more important is to ask yourself, what's the purpose of the test?

If your purpose is to test your system (as opposed to e.g. the integration with external systems), your tests should be repeatable, fast and not include anything you don't own. With repeatable I mean that, if the test fails once it should fail always (no randomness). With fast I mean that you should not have to wait too long for the feedback from running all your tests. With what you own I mean that the tests should not start failing due to changes made outside your organisation. If you can achieve this and still include calls to the database and/or Microsoft HPC, then I don't see any reason why not.

To differerentiate between different test types in NUnit you can use categories. Most tools allow you to run a subset based on these.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Good implementation of unit test with EasyMock

ASP.NET MVC Unit Test Project Entity Framework error

How to determine which .net unit test framework a project is using?

How to generate unit test cases in VS 2017 .net core project?

What to test or not test in acceptance specs?

Unit test large Qt project

How to unit test a vsix project?

Unit test class for Swift project

In Visual Studio native unit test, is it possible to couple unit test to a project?

.NET 6 Unit Test with DependencyResolverHelper

How to unit test a FUSE filesystem implementation?

How to add a unit test project to my existing asp.net core project?

acceptance test method visit undefined

Acceptance test within maven structure?

Devise login acceptance test with capybara

Difference between Acceptance test and Validation?

Difference between acceptance test and functional test?

Should a unit test project for a .NET Standard library target frameworks other than .NET Core?

Missing Method Exception When Referencing .Net Standard Project From .Net 4.6.1 Unit Test

Scala project Unit Test Sucess in SonarQube

Android Instrumented unit test on project library

How to Unit Test a project with Multiple Configurations

Ignore unit test in native VC++ Project

Unit test fails on Jenkins, not on local (React project)

How to add an assembly reference in unit test project?

VS Unit Test Project missing NuGet packages

(PHP project) (Unit Test Success) (not displayed])

how to test wcf rest services in vs "unit test project"?

Does it matter that Unit Test project template in Visual Studio 2019 is for .NET Framework only?