Comments (5)
Maybe @BeforeClass annotation would be here a solution. It runs a code before any tests
from testing-samples.
Do you need application context in your tests? If not, then just do gradle
jvm tests.
On Nov 22, 2015 4:01 PM, "Marco Rodriguez-Suarez" [email protected]
wrote:
Is there a way to run setup code for tests using AndroidJUnit4.class
before Application.onCreate() is called by Instrumentation?I am using Dagger 2 to inject dependencies in Application.onCreate(). It
would be really useful for testing to first be able to set my Components
with mock dependencies however I'm finding that Application.onCreate always
gets called first before anything else.I've tried using a static { } block and also @BeforeClass but this doesn't
work.â
Reply to this email directly or view it on GitHub
https://github.com/googlesamples/android-testing/issues/70.
from testing-samples.
One thing you can do is create your own ActivityTestRule or override beforeActivityLaunched ()
http://developer.android.com/reference/android/support/test/rule/ActivityTestRule.html#beforeActivityLaunched()
And define the pre operations there.
But if you requeriment is with Dagger2 you can setUp your component with the testDependencies like:
@Before
public void setUp() {
Instrumentation instrumentation = InstrumentationRegistry.getInstrumentation();
DemoApplication app
= (DemoApplication) instrumentation.getTargetContext().getApplicationContext();
TestComponent component = DaggerMainActivityTest_TestComponent.builder()
.mockClockModule(new MockClockModule())
.build();
app.setComponent(component);
component.inject(this);
}
You have a complete example here:
https://github.com/chiuki/android-test-demo
and
http://blog.sqisland.com/2015/04/dagger-2-espresso-2-mockito.html
from testing-samples.
I think this is what you're looking for:
http://developer.android.com/reference/android/support/test/runner/lifecycle/package-summary.html
from testing-samples.
Closing as this is not an issue related to the samples. Please use https://groups.google.com/forum/#!forum/android-testing-support-library
from testing-samples.
Related Issues (20)
- Update versions for release 2022-02-11
- [Feature Request] Please add UriIdlingResources example HOT 1
- Android - hide status and navigation bar completely for an app with nav drawer and app bar. HOT 3
- No information about instrumentation was found in AndroidManifest.xml HOT 3
- getIdlingResource method does not exists HOT 2
- Can we "Test" the tests/examples, by running them on GitHub Actions? HOT 27
- [Espresso]Test instrumentation process crashed. After click action app should restarted but with espresso is crashed HOT 11
- Not able to find the screenshots when run the testing-samples->ui->expresso->ScreenshotSample project HOT 3
- GitHub.test
- Security Policy violation Binary Artifacts HOT 4
- Android ui test runs forever HOT 1
- Blind Helpet
- Ali HOT 1
- Basic sample(in Kotlin) for writing unit tests that mock the Android Framework sample App build is failing HOT 1
- BĂŠbĂŠ HOT 1
- Cannot run tests with Android Test Orchestrator using `adb` HOT 2
- Could not resolve com.android.tools.utp:android-test-plugin-host-additional-test-output:30.3.1 HOT 1
- `captureToBitmap` clips the image to the device screen size HOT 1
- testInstrumentationRunnerArguments clearPackageData in kotlin dsl and recent gradle HOT 1
- Support test validation on GitHub Actions HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
đ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. đđđ
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google â¤ď¸ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from testing-samples.