I want to test a method in a fragment but in this method I call a Toast:
Toast.makeText(getActivity(), getString(R.string.signs), Toast.LENGTH_SHORT).show();
Now I want to test the method with JUnit and Powermockito. For this I want to ignore the Toast. I tried it like this: mock the Toast and ignor toast.show()
Toast toastMock = mock(Toast.class);
doReturn(toastMock).when(Toast.makeText(any(Activity.class), anyString(), Toast.LENGTH_SHORT));
doNothing().when(toastMock).show();
But I always get a RuntimeException, because I call Toast without creating a new toast object. How can I bypass this problem?