{"id":20662036,"url":"https://github.com/kilemonn/mock-all","last_synced_at":"2026-04-20T17:02:27.734Z","repository":{"id":224652584,"uuid":"679645714","full_name":"Kilemonn/Mock-All","owner":"Kilemonn","description":"A test mock utility library built on top of Mockito to simplify context configuration for test classes.","archived":false,"fork":false,"pushed_at":"2025-01-25T11:04:19.000Z","size":115,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-01-25T11:26:08.340Z","etag":null,"topics":["auto-mocking","java","jitpack","kotlin","mocking","mockito","test-context","unit-test-context","unit-testing"],"latest_commit_sha":null,"homepage":"","language":"Kotlin","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Kilemonn.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-08-17T09:53:06.000Z","updated_at":"2025-01-25T11:04:23.000Z","dependencies_parsed_at":"2024-06-12T07:02:30.042Z","dependency_job_id":"7097a5ec-8261-41ba-a6a9-a1ea15346e18","html_url":"https://github.com/Kilemonn/Mock-All","commit_stats":null,"previous_names":["kilemonn/mock-all"],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Kilemonn%2FMock-All","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Kilemonn%2FMock-All/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Kilemonn%2FMock-All/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Kilemonn%2FMock-All/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Kilemonn","download_url":"https://codeload.github.com/Kilemonn/Mock-All/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":242793060,"owners_count":20185949,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["auto-mocking","java","jitpack","kotlin","mocking","mockito","test-context","unit-test-context","unit-testing"],"created_at":"2024-11-16T19:12:39.509Z","updated_at":"2026-04-20T17:02:27.672Z","avatar_url":"https://github.com/Kilemonn.png","language":"Kotlin","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Mock-All\r\n\r\n[![CI Build](https://github.com/Kilemonn/Mock-All/actions/workflows/gradle.yml/badge.svg)](https://github.com/Kilemonn/Mock-All/actions/workflows/gradle.yml) [![Coverage](.github/badges/jacoco.svg)](https://github.com/Kilemonn/Mock-All/actions/workflows/gradle.yml)\r\n\r\nA test mock utility library built on top of [Mockito](https://github.com/mockito/mockito) to simplify context configuration for test classes.\r\nIdeally this library should not be required, but in scenarios where you want to setup isolated test configurations quickly this is an option especially when working with existing code with limited tests.\r\n\r\n## Including Dependency\r\n\r\nThis can be included by making sure that you have [JitPack](https://jitpack.io) setup within your project. You can refer to the hosted versions of this library at [Mock-All](https://jitpack.io/#Kilemonn/Mock-All).\r\n\r\nHere is an example in Gradle to include the dependency for test:\r\n```\r\ntestImplementation(\"com.github.Kilemonn:mock-all:0.1.4\")\r\n```\r\n\r\n## Usage\r\n\r\nThere are two components to this library that when used together that allows you to control which beans are excempt from the auto mocking (allowing a default initialised bean to be used) and which beans will be created as a `spy`.\r\n\r\nMake sure you add the following configuration to your maven/gradle test configuration so that reflection can be used.\r\nHere is an example for gradle:\r\n```\r\njvmArgs(\"--add-opens\", \"java.base/java.util=ALL-UNNAMED\", \"--add-opens\", \"java.base/java.lang=ALL-UNNAMED\")\r\n```\r\n\r\n### Mock all\r\n\r\nFirstly you need to mark the test class with the following annotation:\r\n```java\r\n@TestExecutionListeners(MockAllExecutionListener::class)\r\n```\r\n\r\n**With only this annotation present all wired beans in the test class and linked in test contexts will be automatically mocked.**\r\n\r\n### Skip Mocking (Create actual objects)\r\n\r\nThere are likely scenarios where you would want to make sure actual objects are used instead of mocks. Most likely the class(es) you are actually testing.\r\nIf you want to skip wiring of any object you can add this annotation to that member. This annotation is used later to drive spy beans.\r\n\r\n```java\r\n@NotMocked\r\n```\r\n\r\nCurrently these objects annotated with `@NotMocked` will be created via its default zero argument constructor.\r\n\r\n### Initialise as Spy\r\n\r\nSimilarly to how objects are marked to be created as actual objects, you can provide a list of classes that should be initialised as spy objects instead of mocks during the initialisation.\r\n```java\r\n@NotMocked([PermissionChecker.class, RoleChecker.class])\r\n```\r\n\r\nPlease refer to the unit tests for examples of how this mocking is put into action.\r\n\r\n**NOTE: The following will result in \"MyObject\" being created as a spy because it is provided in the spy object list.**\r\n```java\r\n@Autowired\r\n@NotMocked([MyObject.class])\r\nprivate MyObject obj;\r\n```\r\n\r\n### Accessing Mocked/Spyed Instances\r\n\r\nMocked/Spied instances can be requested via the static method:\r\n```java\r\nMockAllExecutionListener.getInstance(clazz: Class\u003c*\u003e): Any?\r\n```\r\n\r\nIf there is inheritance involved, there are other utility methods in `MockAllExecutionListener` to work with hierarchy object look up.\r\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkilemonn%2Fmock-all","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkilemonn%2Fmock-all","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkilemonn%2Fmock-all/lists"}