alibaba / alibaba/testable-mock

Android 项目无法Mock

Open
#142 13 comments 0 reactions 0 assignees View on GitHub
Dominant language
Java
Stars
1.8k
Forks
306
PR merge metrics
No merged PRs in 30d

Description

@MockWith(AuthorPageViewModel.class)
public class AuthorPageViewModelTest {
AuthorPageViewModel model;

public static class Mock {
@MockMethod(targetClass = AuthorPageViewModel.class, targetMethod = "attachDeviceInfo", scope = MockScope.GLOBAL)
private void attachDeviceInfo(Application application) {
return;
}
}

public AuthorPageViewModelTest() {
model = OmniConstructor.newInstance(AuthorPageViewModel.class);
}

@Test
public void fetchData() {
model.fetchAuthorInfo("999");
}
}

Contributor guide

No contributing guide indexed for this repository

Research direction

Start with the AuthorPageViewModelTest example and reproduce the Android failure around @MockWith, @MockMethod, MockScope.GLOBAL, and OmniConstructor.newInstance. Inspect how the test invokes attachDeviceInfo and fetchAuthorInfo, then verify the intended mock behavior works in this test on Android.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
mobile-dev, testing
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.