Skip to content

Instantly share code, notes, and snippets.

View pedrovgs's full-sized avatar
😃

Pedro Gómez pedrovgs

😃
View GitHub Profile
@pedrovgs
pedrovgs / ScreenshotTest.kt
Last active November 22, 2019 12:50
Interface you can import from your tests to be able to use screenshot testing for Android with different resolutions easily
import android.app.Activity
import android.app.Dialog
import android.content.Context
import android.view.View
import androidx.fragment.app.Fragment
import androidx.test.platform.app.InstrumentationRegistry
import androidx.test.platform.app.InstrumentationRegistry.getInstrumentation
import com.facebook.testing.screenshot.Screenshot
import com.facebook.testing.screenshot.ViewHelpers
@pedrovgs
pedrovgs / MockWebServerTest.kt
Created December 12, 2019 09:22
Utility class to use mock web server in our tests
import com.google.gson.Gson
import com.google.gson.JsonElement
import com.google.gson.JsonParser
import okhttp3.Headers
import okhttp3.mockwebserver.MockResponse
import okhttp3.mockwebserver.MockWebServer
import okhttp3.mockwebserver.RecordedRequest
import org.apache.commons.io.FileUtils
import org.junit.After
@pedrovgs
pedrovgs / compressFiles.sh
Last active December 4, 2020 08:40
Manga Time!! Add these files to your path and from any folder execute mangaTime.sh or compressFiles.sh <FOLDER> to transform a folder with a set of images into a zip folder
#!/bin/bash
if [ -z "$1" ]; then
echo "Help : To compress file use argument with directory"
exit 0
fi
filename="${1}.cbz"
if [ -e "$filename" ]; then
@pedrovgs
pedrovgs / TestConfig.kt
Created January 17, 2020 16:28
How to check if I'm running tests with robolectric or instrumentation tests
package com.github.pedrovgs
object TestConfig {
val runningTests by lazy {
isRunningUITests() || isRunningRobolectricTests()
}
private fun isRunningRobolectricTests(): Boolean = checkIfClassIsAvailable("org.robolectric.RobolectricTestRunner")
private fun isRunningUITests(): Boolean = checkIfClassIsAvailable("com.github.pedrovgs.MyAndroidTestRunner")
@pedrovgs
pedrovgs / IsRunningTests.swift
Created January 17, 2020 16:31
How to check if I'm running tests in iOS
import Foundation
class IsRunningTests {
static func check() -> Bool {
guard let value = ProcessInfo.processInfo.environment["IS_RUNNING_TESTS"] else {
return false
}
return value == "true"
}
@pedrovgs
pedrovgs / ComposeViewModel.kt
Created April 28, 2021 16:58
Example of a base view model for Jetpack Compose
import androidx.lifecycle.*
import kotlinx.coroutines.CoroutineDispatcher
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
abstract class ComposeViewModel<C, E> : ViewModel(), LifecycleObserver {