我有類handleFirebaseMessages
。它包含功能onMessageReceived()
。該功能負責接收數據和創建通知。 onMessageReceived()
在RemoteMessages
對象接收數據。我正在爲這個函數寫一個測試。但我還沒有完全掌握。如何使android單元測試通知?
HandleFirebaseMessages
public class HandleFirebaseMessages extends FirebaseMessagingService {
@Override
public void onMessageReceived(final RemoteMessage remoteMessage) {
final Map<String, String> data = remoteMessage.getData();
//create notifications using NotificationCompat.Builder
}
}
我已經能夠編寫測試代碼的一部分。我如何完成此操作?
@Test
public void testHandleFirebaseMessages() throws Exception {
Map<String,String> data=new HashMap<String,String>();
data.put("id","4422");
data.put("type", "1");
data.put("imageUrl" , "https://image.freepik.com/free-vector/android-boot-logo_634639.jpg");
data.put("smallTitle" , "DoJMA v2");
data.put("smallSubTitle", "Update now from Google Play Store");
data.put("ticker" , "New update for DoJMA");
data.put("contentInfo" , "");
data.put("link" , "https://photo2.tinhte.vn/data/avatars/l/1885/1885712.jpg?1402763583");
data.put("className" , "HomeActivity");
data.put("page" , "2");
data.put("bigTitle" , "DoJMA Android app version 2 released!");
data.put("bigSubTitle" , "Hi folks! New DoJMA update is here! Major redesigning and improvements! This app was made by the Mobile App Club.They work really hard man...and get good products");
data.put("bigSummaryText" , "Update now");
RemoteMessage message = new RemoteMessage.Builder("1")
.setMessageId("1")
.setData(data)
.build();
(new HandleFirebaseMessages()).onMessageReceived(message);
//WHat now?
}