Skip to content

Commit

Permalink
Update the homepage
Browse files Browse the repository at this point in the history
This PR refreshes the layout of the homepage:
- The Robolectric logo is now fully transparent.
- There is now a code sample in Kotlin.
- The table of content on the right is gone.
- The four sections at the bottom are now displayed in cards.
  • Loading branch information
MGaetan89 committed Sep 23, 2024
1 parent ea2c526 commit 9506152
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 28 deletions.
Binary file removed docs/images/logotype.png
Binary file not shown.
Binary file added docs/images/robolectric-horizontal.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
87 changes: 60 additions & 27 deletions docs/index.md
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>
5 changes: 5 additions & 0 deletions docs/stylesheets/extra.css
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,8 @@
width: 13rem;
}
}

/* Make the grid layout use at most 2 columns. */
.md-typeset .grid {
grid-template-columns: repeat(auto-fit, minmax(24rem, 1fr))
}
2 changes: 2 additions & 0 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@ extra_css:
- stylesheets/extra.css

markdown_extensions:
- attr_list
- github-callouts
- md_in_html
- pymdownx.highlight:
anchor_linenums: true
line_spans: __span
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
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
Expand Down

0 comments on commit 9506152

Please sign in to comment.