chiuki / android-test-demo Goto Github PK
View Code? Open in Web Editor NEWAndroid testing with Dagger 2, Espresso 2 and Mockito
License: Apache License 2.0
Android testing with Dagger 2, Espresso 2 and Mockito
License: Apache License 2.0
It's too central the current way. In the activity, it scales up.
I'm trying to run your project in Android studio bug I'm finding a problem. Dagger does not seem to generate the Dagger class for the TestComponent defined in ActivityLauncher. I found the same issue in my own code and I'd like to know if there is anything else I'm supposed to do. ActivityLauncher line 34 shows an error where DaggerActivityLauncher_TestComponent is not found.
DemoApplication app
= (DemoApplication) fetchInstrumentation().getTargetContext().getApplicationContext();
TestComponent component = DaggerActivityLauncher_TestComponent.builder()
.mockClockModule(new MockClockModule())
.build();
app.setComponent(component);
Thanks!
First of all, thank you very much for the wonderful repo. This really helped me write Espresso for our existing app
My issue is around running the test - executing via the gradle wrapper runs the test correctly - but running it via studio executes the ff.
adb shell am instrument -w -r -e debug false -e class nz.co.blah.ui.MainActivityTest nz.co.blah.test/android.support.test.runner.AndroidJUnitRunner
Which is wrong because it should be executing my custom AndroidJUnitRunner. Do you happen to know how to edit this? I've made the instrumentation test gradle aware but it doesn't seem to call the appropriate runner.
If I import your project into Android Studio DaggerMainActivityTest_TestComponent cannot be resolved.
TestComponent component = DaggerMainActivityTest_TestComponent.builder()
.mockClockModule(new MockClockModule())
.build();
The DemoApplication
exposes a setComponent
method to the outside world. I understand you need to do that in order to make your tests set the test component to provide mocks, but anyone can call that method and break your app.
I think that DemoApplication
and MainActivity
should get their components somehow by not exposing their internals to the outside world, as that would violate the hiding principle.
Or am I missing something else?
Anyway, thanks for your demo! :)
Not sure this is really an issue, but I found it to be interesting.
It seems that when executing the tests, DemoApplication
's onCreate()
method is called before setComponent()
, so both the normal component and the test components are initialised before every test. (The if component == null
check in onCreate()
will always be true).
Is this a problem? Or we don't really care, just so long as it's called before an Activity
's onCreate()
?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.