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

Unit tests for exceptions are failing 'in harmony' (.NET 7) #39

Open
geertdoornbos opened this issue Jan 11, 2023 · 3 comments
Open

Unit tests for exceptions are failing 'in harmony' (.NET 7) #39

geertdoornbos opened this issue Jan 11, 2023 · 3 comments

Comments

@geertdoornbos
Copy link

Tests for exceptions are created using InternalMock. It's constructed using:

service.Mock(methodName).Throws(exception)

The InternalMock implementation depends on Harmony to patch private methods.

This patching fails in some situations:

  • running tests in test explorer ('Run') fails
  • running tests using 'dotnet test -c Debug' fails
  • running tests using 'dotnet test -c Release' fails

but, running tests in test explorer ('Debug') succeeds

The cause seems to be originated in MonoMod.Common as mentioned in Harmony issue 504

Waiting for .NET 7 support might not be the way forward pardeike/Harmony#504 (comment)

@TehWardy
Copy link
Collaborator

TehWardy commented Feb 1, 2024

It's been an ongoing issue discussed in the standard community with the InternalMock library.
recently though a solution to this problem was proposed in that library.

I think we just need to regroup the team and discuss progress on the two projects so we can rekindle that progress ...
https://github.com/cjdutoit/PartialMock.Demo

@robertmclaws
Copy link

I feel like if we're having to mock things for testing then we need to ask if we're on the wrong track. I've been able to guarantee stability with Restier using extensive internal unit tests and clean, simple integration tests.

It's a problem easily solved by disallowing private methods and marking everything internal instead.

@TehWardy
Copy link
Collaborator

That's an interesting take.
I'm not sure how that would fit with the standard though it's worth raising with @hassanhabib for a deeper discussion.

For me I previously raised a concern that testing private methods was effectively testing implementation details which in unit testing circles is often referred to as an anti-pattern behaviour.

Marking the methods internal instead actually solves the need to use Harmony at all.

I think there's some interesting "ethos" discussions to be had in this area that affects the entire standard community, I'd be interested to see what a poll might uncover if we reached enough people for it to be considered an accurate reflection of views.

You do have a point though ...
f it feels like you're fighting the technology you're probably not doing something right and it should be considered a time to internally reflect then ask "am I doing this the right way".

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

No branches or pull requests

3 participants