There is a simple app in android studio written in kotlin.This is the following code in onCreate
val manager = FakeReviewManager(baseContext)
val request = manager.requestReviewFlow()
request.addOnCompleteListener{ request ->
if (request.isSuccessful){
Log.i("message","Rating")
manager.launchReviewFlow(this, request.result).addOnCompleteListener{
Log.i("message","Rating1")
}
}else{
}
}
In Logcat Messages showed successfully. But nothing has showed.How can Fix this this problem?
FakeReviewManager is strictly used for unit test and does not show any UI, if a UI is what you are expecting.
Related
I'm a newbie in unit testing in android and I follow this repository on implementing it but when I done it and run it my test it passes always even if I make a different clear assertion
like that
MatcherAssert.assertThat(25, CoreMatchers.`is`(20))
so I thought I made something wrong and I tried to clone the repository and try it and found the repository also passed in all cases , I tried to change the MainCoroutineRule from this to this and now the tests work but not passed
for example in Repository test it gives me this error
junit.framework.AssertionFailedError:
Expected :com.fevziomurtekin.deezer.core.data.ApiResult$Loading#5c7933ad
Actual :Success(data=[AlbumData(diskNumber=1, duration=320, explicitContentCover=0, explicitContentLyrics=0,.......
and the method for that test case
#ExperimentalTime
#Test
fun fetchAlbumTracksFromNetworkTest() = runBlocking {
val mockData = AlbumDetailsResponse(data = listOf(MockUtil.album), total = 12)
val returnData = Response.success(mockData)
whenever(service.fetchAlbumDetails(MockUtil.albumID)).thenReturn(returnData)
repository.fetchAlbumTracks(MockUtil.albumID).test {
val result = expectItem()
assertEquals(result, ApiResult.Success(listOf(MockUtil.album)))
Assert.assertEquals((result as ApiResult.Success<List<AlbumData>>).data[0].title, "Alo")
Assert.assertEquals(result.data[0].id, "425605922")
Assert.assertEquals(result.data[1].title, "Geceler")
Assert.assertEquals(result.data[1].id, "425605932")
expectComplete()
}
verify(service, atLeastOnce()).fetchAlbumDetails(MockUtil.albumID)
verifyNoMoreInteractions(service)
}
and for Viewmodel it gives me this error
Argument(s) are different! Wanted:
observer.onChanged(
Success(data=[ArtistAlbumData(cover=https://api.deezer.com/album/51174732/image, cov
for this test case
#Test
fun fetchAlbumListTest() = runBlocking {
val mockList = listOf(MockUtil.album)
val observer : Observer<ApiResult<List<AlbumData>>> = mock()
val fetchedData : LiveData<ApiResult<List<AlbumData>>> = repository.fetchAlbumTracks("302127").asLiveData()
fetchedData.observeForever(observer)
viewModel.fetchingAlbumDatas(MockUtil.albumID)
delay(500L)
verify(observer).onChanged(ApiResult.Success(mockList))
fetchedData.removeObserver(observer)
}
and for Api test here it also fails to read input stream from input json files
Did I setup anything wrong on test configuration which makes the tests fails or the tests itself is wrong,the weird is the repository which I used there are many test classes for the whole project and I wonder if it didn't work it won't be pushed!
update: I open an issue on the repository and it has more details of what happens here
hope anyone can help with that?
I am trying to make an android app connecting to api, and for that I am using Kotlin Coroutines and Retrofit. I was following this tutorial (https://android.jlelse.eu/android-networking-in-2019-retrofit-with-kotlins-coroutines-aefe82c4d777) trying to setup my own api, but I stumbled on a problem. I can't get any data from api because I can't process response.
I don't know much about coroutines, so I don't understand whats the problem here. If I run debug and go line by line it is working perfectly each time, but if I run the app, it only prints TestPoint1. Also it doesn't throw any error and response is always 200 OK. I have tried to combine
val standings = service.getStandings()
and
val response = standings.await()
into one line, after which it doesn't work on debug either. It continues on code after launched coroutine.
val service = ApiFactory.footballApi
GlobalScope.launch(Dispatchers.Main) {
val standings = service.getStandings()
try {
Log.d("TAG", "TestPoint1")
val response = standings.await()
Log.d("TAG", "TestPoint2")
if(response.isSuccessful){
//store data
}else{
Log.d("MainActivity ",response.errorBody().toString())
}
}catch (e: Exception){
Log.d("TAG", "Error")
}
}
Switch the Dispatchers.Main to Dispatchers.IO . You can't make that request on the main thread .
The coroutines require a coroutine context in order to know in what thread they are going to run . For that , the Dispatchers class offer you some options . Currently you are making the request in the Dispatchers.Main which you cannot do because fetching data from the API , requires another thread . IO is the right thread for network calls .
Note :
Also please check : Internet permission, Internet connection .
I'm using ktor for create rest api with kotlin but when i change api and run again response won't change.
This is my code
fun main(args: Array<String>) {
embeddedServer(Netty, port = 8080) {
routing {
get("/") {
call.respondText("Hi", ContentType.Text.Plain)
}
}
}.start(wait = true)
}
When run it for the first time work correct and show in localhost:8080
Hi
But if i change
call.respondText("Hi", ContentType.Text.Plain)
to
call.respondText("Hello", ContentType.Text.Plain)
And run it again response no change and steel show Hi in localhost:8080
Update
If i close android studio and open it again and run its work and show Hello but again if i change anything nothing will be change
i don't have any idea to why this is happening.
It happens with me when android instant run feature is enabled.
Please consider to disable it and try again.
In my app so far, I am displaying a tweet (my own for now) using the Twitter Kit for Android and have a Retweet button with which I am attempting to (go figure) retweet using the Twitter API Client.
Here are the links I referred to before this:
1) Twitter REST APIs from Android
2) Twitter Community Discussion on Retweeting using the TwitterApiClient
This is the code I'm using:
val twApiClient: TwitterApiClient = TwitterCore.getInstance().apiClient
tbTweet.setOnMenuItemClickListener {
when (it.itemId) {
R.id.item_retweet -> {
val call: Call<Tweet> = twApiClient.statusesService.retweet(tweetID, true)
Log.i("Retweet", if (call.isExecuted) "Successful" else "Failed")
}
}
true
}
I'm not getting any errors but when I go to my Profile Page on twitter, the retweet doesn't show up. The same problem has been stated in the 2nd link I provided, but no solution was given.
I also Log out the Execution Status. It comes as "Failed", so I know that the call retweet() isn't even executing. But why?
What is the problem and how do I fix it?
So, apparently the code above is incomplete. You have to call execute() on the call object that is returned from the retweet(tweetId, true) method. And then, you can call an onCompleteListener to see if your retweet was successful or not.
I meet problem in JSONStore init function in Android. It will hang for about 10 minutes until then the JSONStore gives me the init result callback. This did occur only in Android and iPhone works fine. I can give the reproduce procedure:
Install my app in a 'clean' Android, which has not install the app before.
Successfully init the JSONStore by my arguemnts (I will attach the code below).
Then I re-install my app, note that I did't uninstall it but just replace it with a new build.
After replace I'm using the same auth try to init JSONStore, but it hangs....(Maybe will give the result callback at 10 minutes or longer, no error handlers trigger).
If a kill the app and re-launch it, then this time the JSONStore init very fast and works fine
I debug the App with inspect and I'm sure this is the problem that WL.JSONStore.init didn't give me result callback that hangs app. I don't know the reason why the first time need to consume so much time. Anyone meet the same issue as me?
var options = {password:pscd,localKeyGen:true};
var promise =
WL.JSONStore.init(data_collection, options).then(function(){
console.info("init json store successfully!");
return true;
}).fail(function (errorObject) {
console.info("init json store failed!" + errorObject);
return false;
});
return promise;
I just tried out the following code in the same 6.1 build that you have, and it is working fine for me on both the Android Emulator and a Nexus 4:
var data_collection = {people : {
searchFields : {name : 'string', age : 'integer'}
}
};
var pscd = "samplepassword";
var options = {password:pscd,localKeyGen:true};
var promise =
WL.JSONStore.init(data_collection, options).then(function(){
alert("init json store successfully!");
return true;
}).fail(function (errorObject) {
alert("init json store failed!" + errorObject);
return false;
});
return promise;
The only thing that might be different to your code is what your password or your data_collection variables are. Could you add more details regarding what data_collection is?