This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Future<Response> get(String url) async { | |
String wsseHeader = await generateAuthHeader(); | |
final response = await httpClient.get(url, | |
headers: { | |
HttpHeaders.contentTypeHeader: 'application/vnd.api+json', | |
'Authorization': 'WSSE profile="UsernameToken"', | |
'X-WSSE': wsseHeader | |
}, | |
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Calculator { | |
fun sum(a: Int, b: Int) = a + b | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@HiltViewModel | |
class CalculatorViewModel @Inject constructor( | |
private val calculator: Calculator | |
) : ViewModel() { | |
... | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@AndroidEntryPoint | |
class CalculatorActivity : AppCompatActivity() { | |
private val viewModel: CalculatorViewModel by viewModels() | |
... | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Module | |
@InstallIn(SingletonComponent::class) | |
class AppModule { | |
@Singleton | |
@Provides | |
fun provideCalculator(): Calculator = Calculator() | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Before | |
fun setUp() { | |
calculatorService = mockk<CalculatorService>() | |
viewModel = CalculatorViewModel(calculatorService) | |
} | |
@Test | |
fun test_SumReturnFromCalculator_LiveDataChanged() { | |
//Given | |
every { calculatorService.sum(a, b) } returns sum |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class TestRunner : AndroidJUnitRunner() { | |
override fun newApplication(cl: ClassLoader?, name: String?, context: Context?): Application { | |
return super.newApplication(cl, HiltTestApplication::class.java.name, context) | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
android { | |
defaultConfig { | |
... | |
testInstrumentationRunner "com.duyha.hilttestingsample.TestRunner" | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@HiltAndroidTest | |
@RunWith(AndroidJUnit4::class) | |
class CalculatorActivityTest { | |
@BindValue | |
@JvmField | |
val viewModel = mockk<CalculatorViewModel>(relaxed = true) | |
@get:Rule | |
var hiltRule = HiltAndroidRule(this) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Test | |
fun test_DisplaySum_WhenSumLiveDataChange() { | |
//Given | |
val scenario = launchActivity<CalculatorActivity>() | |
//When | |
sum.postValue(10) | |
//Then | |
onView(withId(R.id.tvSum)).check(matches(withText("10"))) | |
} |
OlderNewer