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

Collect all mocks created in a test? #76

Open
TWiStErRob opened this issue Dec 23, 2023 · 2 comments
Open

Collect all mocks created in a test? #76

TWiStErRob opened this issue Dec 23, 2023 · 2 comments
Assignees
Labels

Comments

@TWiStErRob
Copy link

TWiStErRob commented Dec 23, 2023

Adding this to every test class is tedious and error-prone:

@AfterTest
fun verify() {
	verifyNoUnverifiedExpectations(dep1)
	verifyNoUnverifiedExpectations(dep2)
	verifyNoUnverifiedExpectations(dep3)
	verifyNoUnmetExpectations(dep1)
	verifyNoUnmetExpectations(dep2)
	verifyNoUnmetExpectations(dep3)
}

Is there a way to get mocks?

i.e.

@AfterTest
fun verify() {
	mocks().forEach { // runs for dep1, dep2, dep3
		verifyNoUnverifiedExpectations(it)
		verifyNoUnmetExpectations(it)
	}
}

This would enable nice abstractions and helper methods to reduce boilerplate.

(Might require a Mocker stateholder similar to MocKMP. I chose your library because MocKMP is full of workarounds hacks and weird APIs.)

@Nillerr
Copy link
Collaborator

Nillerr commented Apr 13, 2024

Hi @TWiStErRob

Sorry for my hiatus from the project. I like this suggestion, and I believe we could generate code to do something like this instead:

@AfterTest
fun verify() {
    verifyMockative(this)
}

I'll have a look as to whether we can generate a function for every test class, which would access the test properties and verify them.

@TWiStErRob
Copy link
Author

Try to separate/enable the two different verifyNo classes in the API as they're significantly different functionality.

@Nillerr Nillerr self-assigned this Apr 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants