代码部分中的下面发布的方法包含一个静态方法,即"with()".我想测试下面的代码,所以我编写了这个方法的测试,如测试部分所示.
我尝试使用"spy()"和"mock()"测试方法,但测试失败了alwyas.
请让我知道如何测试方法返回void?
码
public RequestCreator requestCreatorFromUrl(String picUrl) {
return Picasso.with(mCtx).load(picUrl);
}
Run Code Online (Sandbox Code Playgroud)
测试:
public class ValidationTest {
@Mock
private Context mCtx = null;
@Rule
public MockitoRule mockitoRule = MockitoJUnit.rule();
@Before
public void setUp() throws Exception {
mCtx = Mockito.mock(Context.class);
Assert.assertNotNull("Context is not null", mCtx);
}
@Test
public void whenRequestCreatorFromUrlTest() throws Exception {
Picasso picasso = Picasso.with(mCtx);
Picasso spyPicasso = spy(picasso);
Uri mockUri = mock(Uri.class);
RequestCreator requestCreator = Picasso.with(mCtx).load(mockUri);
RequestCreator spyRequestCreator = spy(requestCreator);
doReturn(spyRequestCreator).when(spyPicasso.load(mockUri));
//when(spyPicasso.load(mockUri)).thenReturn(spyRequestCreator);
RequestCreator actual = spyPicasso.load(mockUri);
Assert.assertEquals(requestCreator, …Run Code Online (Sandbox Code Playgroud) 我尝试从源代码编译安装后尝试启动mysql服务器时,在MAC OS X 10.11中遇到以下错误。keyring_file不可读。
我试图使用以下命令启动服务器。
./mysqld start
Run Code Online (Sandbox Code Playgroud)
终端中产生跟随错误。
2016-03-24T18:43:50.591772Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2016-03-24T18:43:50.592053Z 0 [Warning] Insecure configuration for --secure-file-priv: Current value does not restrict location of generated files. Consider setting it to a valid, non-empty path.
2016-03-24T18:43:50.592091Z 0 [Note] ./mysqld (mysqld 5.7.11) starting as process 3470 ...
2016-03-24T18:43:50.593833Z 0 [Warning] Can't create test file /usr/local/mysql/data/Hemens-MacBook-Pro-2.lower-test
2016-03-24T18:43:50.593852Z 0 [Warning] Can't create test file /usr/local/mysql/data/Hemens-MacBook-Pro-2.lower-test
2016-03-24T18:43:50.595428Z …Run Code Online (Sandbox Code Playgroud)