Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
brand engager
Mar 23, 2011

Another weird thing, I added this below that Text
Kotlin code:
if (name != "unknown") Text(name)
This one does appear when the state updates, but the original Text still shows the old state

Adbot
ADBOT LOVES YOU

brand engager
Mar 23, 2011

Anyone used mockk to mock extension functions on a singleton object before? I cant figure out any combination of mockkStatic or mockkObject that works. The specific thing I need to mock is google's firebase initialization, they've got it declared like
Kotlin code:
object Firebase

fun Firebase.initialize(context: Context): FirebaseApp? = FirebaseApp.initializeApp(context)

//some overloads below of that function that I'm not trying to mock for our tests
The documentation is this huge page with a few examples but it's not good https://mockk.io/#extension-functions
I don't know why google made those extension functions in the same file instead of just being part of the object either, real pain in the rear end. FirebaseApp is in java instead of kotlin

brand engager
Mar 23, 2011

Forgot they have the source on github, this is the specific function I was trying to mock for tests
https://github.com/firebase/firebas...Firebase.kt#L48

brand engager
Mar 23, 2011

I'm trying to mock the initialize function, not a context param

brand engager
Mar 23, 2011

You really aren't getting it

brand engager
Mar 23, 2011

Trying to setup unit tests for this analytics implementation we have that relies on firebase. For whatever reason google wrote the functions on the firebase object as extension functions which is making it difficult or impossible to mock those functions. I'll probably end up wrapping all the calls with another object that just directly forwards them without any additional logic to minimize the amount of untested code.

brand engager
Mar 23, 2011

Extension functions are pretty awkward in general for testing, since they don't actually "belong" to the object. Like if I had some type named Thing and in a file named Extensions.kt I wrote
Kotlin code:
// File is Extensions.kt

fun Thing.doIt(text: String) {
    // do whatever here
}
This results in some java code that looks something like
Java code:
public static class ExtensionsKt {
    public static void doIt(Thing thing, String text) {
        // do whatever here
    }
}
so the function is part of some entirely separate object and calls doIt on mock instances of Thing still go to the unmocked extension function. This is really annoying for reading unit tests because non-extensions on that object are mocked but extensions aren't.

Adbot
ADBOT LOVES YOU

brand engager
Mar 23, 2011

Yeah you can just unzip an apk, though it sounds like this is a game so the game data might be in some framework-specific format instead of PNGs

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply