forked from robolectric/robolectric.github.io
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update the homepage (robolectric#320)
- Loading branch information
Showing
6 changed files
with
68 additions
and
28 deletions.
There are no files selected for viewing
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,51 +1,84 @@ | ||
--- | ||
hide: | ||
- navigation | ||
- toc | ||
--- | ||
|
||
<div align="center"> | ||
<img src="images/logotype.png" alt="{{ config.site_name }}" /> | ||
<img src="images/robolectric-horizontal.png" alt="{{ config.site_name }}" /> | ||
|
||
<h1>{{ config.site_description }}</h1> | ||
</div> | ||
|
||
Running tests on an Android emulator or device is slow! Building, deploying, and launching the app often takes a minute or more. That's no way to do <abbr title="Test-Driven Development">TDD</abbr>. There must be a better way. | ||
Running tests on an Android emulator or device is slow! Building, deploying, and running the tests often take minutes. That's no way to do <abbr title="Test-Driven Development">TDD</abbr>. There must be a better way. | ||
Robolectric is a framework that brings fast and reliable unit tests to Android. Tests run inside the JVM in seconds. With Robolectric you can write tests like this: | ||
|
||
[Robolectric]({{ config.site_url }}) is a framework that brings fast and reliable unit tests to Android. Tests run inside the JVM on your workstation in seconds. With Robolectric you can write tests like this: | ||
=== "Java" | ||
|
||
```java | ||
@RunWith(RobolectricTestRunner.class) | ||
public class MyActivityTest { | ||
@Test | ||
public void clickingButton_shouldChangeMessage() { | ||
try (ActivityController<MyActivity> controller = Robolectric.buildActivity(MyActivity.class)) { | ||
controller.setup(); // Moves Activity to RESUMED state | ||
MyActivity activity = controller.get(); | ||
```java | ||
@RunWith(RobolectricTestRunner.class) | ||
public class MyActivityTest { | ||
@Test | ||
public void clickingButton_shouldChangeMessage() { | ||
try (ActivityController<MyActivity> controller = Robolectric.buildActivity(MyActivity.class)) { | ||
controller.setup(); // Moves the Activity to the RESUMED state | ||
MyActivity activity = controller.get(); | ||
|
||
activity.findViewById(R.id.button).performClick(); | ||
assertEquals(((TextView) activity.findViewById(R.id.text)).getText(), "Robolectric Rocks!"); | ||
activity.findViewById(R.id.button).performClick(); | ||
assertEquals(((TextView) activity.findViewById(R.id.text)).getText(), "Robolectric Rocks!"); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
``` | ||
[» Getting Started...](getting-started.md) | ||
``` | ||
|
||
=== "Kotlin" | ||
|
||
```kotlin | ||
@RunWith(RobolectricTestRunner::class) | ||
class MyActivityTest { | ||
@Test | ||
fun clickingButton_shouldChangeMessage() { | ||
Robolectric.buildActivity(MyActivity::class).use { controller -> | ||
controller.setup() // Moves the Activity to the RESUMED state | ||
val activity = controller.get() | ||
|
||
activity.findViewById(R.id.button).performClick() | ||
assertEquals((activity.findViewById(R.id.text) as TextView).text, "Robolectric Rocks!") | ||
} | ||
} | ||
} | ||
``` | ||
|
||
[Get started](getting-started.md){ .md-button .md-button--primary } | ||
|
||
<div class="grid cards" markdown> | ||
|
||
- **Test APIs & Isolation** | ||
|
||
--- | ||
|
||
### Test APIs & Isolation | ||
Unlike traditional emulator-based Android tests, Robolectric tests run inside a sandbox which allows the Android environment to be precisely configured to the desired conditions for each test, isolates each test from its neighbors, and extends the Android framework with test APIs which provide minute control over the Android framework's behavior and visibility of state for assertions. | ||
|
||
Unlike traditional emulator-based Android tests, Robolectric tests run inside a sandbox which allows the Android environment to be precisely configured to the desired conditions for each test, isolates each test from its neighbors, and extends the Android framework with test APIs which provide minute control over the Android framework's behavior and visibility of state for assertions. | ||
While much of the Android framework will work as expected inside a Robolectric test, some Android components' regular behavior doesn't translate well to unit tests: hardware sensors need to be simulated, system services need to be loaded with test fixture data. In those cases, Robolectric provides a [test double](https://en.wikipedia.org/wiki/Test_double) that's suitable for most unit testing scenarios. | ||
|
||
While much of the Android framework will work as expected inside a Robolectric test, some Android components' regular behavior doesn't translate well to unit tests: hardware sensors need to be simulated, system services need to be loaded with test fixture data. In those cases, Robolectric provides a [test double](https://en.wikipedia.org/wiki/Test_double) that's suitable for most unit testing scenarios. | ||
- **No Mocking Frameworks Required** | ||
|
||
### Run Tests Outside of the Emulator | ||
--- | ||
|
||
Robolectric lets you run your tests on your workstation, or on your continuous integration environment in a regular JVM, without an emulator. Because of this, the dexing, packaging, and installing-on-the emulator steps aren't necessary, reducing test cycles from minutes to seconds so you can iterate quickly and refactor your code with confidence. | ||
An alternate approach to Robolectric is to use mock frameworks such as [Mockito](https://site.mockito.org/) or to mock out the Android SDK. While this is a valid approach, it often yields tests that are essentially reverse implementations of the application code. | ||
|
||
### SDK, Resources, & Native Method Simulation | ||
Robolectric allows a test style that is closer to black box testing, making the tests more effective for refactoring and allowing the tests to focus on the behavior of the application instead of the implementation of Android. You can still use a mocking framework along with Robolectric if you like. | ||
|
||
Robolectric handles inflation of views, resource loading, and lots of other stuff that's implemented in native C code on Android devices. This allows tests to do most things you could do on a real device. It's easy to provide your own implementation for specific SDK methods too, so you could simulate error conditions or real-world sensor behavior, for example. | ||
- **Run Tests Outside the Emulator** | ||
|
||
### No Mocking Frameworks Required | ||
--- | ||
|
||
An alternate approach to Robolectric is to use mock frameworks such as [Mockito](https://site.mockito.org/) or to mock out the Android SDK. While this is a valid approach, it often yields tests that are essentially reverse implementations of the application code. | ||
Robolectric lets you run your tests on your workstation, or on your continuous integration environment, in a regular JVM, without an emulator. Because of this, the dexing, packaging, and installing steps aren't necessary, reducing test cycles from minutes to seconds so you can iterate quickly and refactor your code with confidence. | ||
|
||
Robolectric allows a test style that is closer to black box testing, making the tests more effective for refactoring and allowing the tests to focus on the behavior of the application instead of the implementation of Android. You can still use a mocking framework along with Robolectric if you like. | ||
- **SDK, Resources, & Native Method Simulation** | ||
|
||
--- | ||
|
||
Robolectric handles inflation of `View`s, resource loading, and lots of other stuff that's implemented in native C code on Android devices. This allows tests to do most things you could do on a real device. You can provide your own implementation for specific SDK methods too, so you could simulate error conditions or real-world sensor behavior, for example. | ||
|
||
</div> |
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
Babel==2.16.0 | ||
babel==2.16.0 | ||
certifi==2024.8.30 | ||
charset-normalizer==3.3.2 | ||
click==8.1.7 | ||
|