Skip to content

Commit

Permalink
Create Mkdocs config
Browse files Browse the repository at this point in the history
  • Loading branch information
MGaetan89 committed Apr 15, 2024
1 parent b1e39f5 commit ad00deb
Show file tree
Hide file tree
Showing 24 changed files with 181 additions and 112 deletions.
8 changes: 1 addition & 7 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
_site
build
.idea
.bundle
.sass-cache
.DS_Store
*.iml
*.ipr
*.iws
vendor
.jekyll-cache
.jekyll-metadata
site/
6 changes: 2 additions & 4 deletions androidx_test.md → docs/androidx_test.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
---
title: AndroidX Test
group: User Guide
order: 1
redirect_from: "/activity-lifecycle/"
hide:
- footer
---

# AndroidX Test
Expand Down
9 changes: 4 additions & 5 deletions automated-migration.md → docs/automated-migration.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
---
title: Automated Migration
group: [hide]
order: 7
toc: true
redirect_from: "/errorprone-refactorings/"
hide:
- footer
- navigation
- toc
---

# Automated Migration
Expand Down
6 changes: 3 additions & 3 deletions best-practices.md → docs/best-practices.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
title: Best Practices
group: User Guide
order: 8
hide:
- footer
- toc
---
# Best Practices

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
title: Build System Integration
group: Customizing
order: 2
hide:
- footer
- toc
---

# Build System Integration
Expand All @@ -13,6 +13,7 @@ This gives build system implementors the ability to perform manifest, asset and
This supersedes Robolectric's support for merging multiple libraries specified via `@Config(libraries = {"lib1", "lib2"})` and `project.properties` support from legacy Eclipse ADT projects.

Keys in the file:

* `android_merged_manifest`: Full path to the project's merged `AndroidManifest.xml` file.
* `android_merged_resources`: Full path to the project's merged resources.
* `android_merged_assets`: Full path to the project's merged assets.
Expand Down
6 changes: 2 additions & 4 deletions building-robolectric.md → docs/building-robolectric.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
---
title: Building Robolectric
group: Contributing
order: 1
toc: true
hide:
- footer
---

# Building Robolectric
Expand Down
18 changes: 7 additions & 11 deletions configuring.md → docs/configuring.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
---
title: Configuring Robolectric
group: User Guide
order: 2
hide:
- footer
---

# Configuring Robolectric
Expand All @@ -15,7 +14,7 @@ To configure Robolectric for a single test class or method, use the <a href="/ja
Base classes are also searched for annotations, so if you find yourself specifying the same values on a large number of tests, you can create a base class and move your `@Config` annotation to that class.

```java
@Config(sdk=JELLYBEAN_MR1,
@Config(sdk=KITKAT,
shadows={ShadowFoo.class, ShadowBar.class})
public class SandwichTest {
}
Expand All @@ -29,7 +28,7 @@ Below is an example:

```properties
# src/test/resources/com/mycompany/app/robolectric.properties
sdk=18
sdk=19
shadows=my.package.ShadowFoo,my.package.ShadowBar
```

Expand All @@ -48,11 +47,10 @@ The following examples show how to handle common configuration tasks. For clarit
By default, Robolectric will run your code against the `targetSdkVersion` specified in your manifest. If you want to test your code under a different SDK, you can specify the SDK using the `sdk`, `minSdk` and `maxSdk` config properties:

```java
@Config(sdk = { JELLY_BEAN, JELLY_BEAN_MR1 })
@Config(sdk = { KITKAT, LOLLIPOP })
public class SandwichTest {

public void getSandwich_shouldReturnHamSandwich() {
// will run on JELLY_BEAN and JELLY_BEAN_MR1
// will run on KITKAT and LOLLIPOP
}

@Config(sdk = KITKAT)
Expand All @@ -78,7 +76,6 @@ Robolectric will attempt to create an instance of your Application class as spec
```java
@Config(application = CustomApplication.class)
public class SandwichTest {

@Config(application = CustomApplicationOverride.class)
public void getSandwich_shouldReturnHamSandwich() {
}
Expand All @@ -91,15 +88,14 @@ You can explicitly configure the set of resource qualifiers in effect for a test

```java
public class SandwichTest {

@Config(qualifiers = "fr-xlarge")
public void getSandwichName() {
assertThat(sandwich.getName()).isEqualTo("Grande Croque Monégasque");
}
}
```

See [Using Qualifiers](/using-qualifiers) for more details.
See [Using Qualifiers](using-qualifiers.md) for more details.

## System Properties

Expand Down
8 changes: 3 additions & 5 deletions contributing.md → docs/contributing.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
---
title: Contributor Guidelines
group: Contributing
order: 1
toc: true
hide:
- footer
---

# Contributor Guidelines

## Getting Started

The first step to contributing is to ensure that you are able to build Robolectric. Please visit [building Robolectric](/building-robolectric/) for more details and instructions on setting up an environment to build Robolectric.
The first step to contributing is to ensure that you are able to build Robolectric. Please visit [building Robolectric](building-robolectric.md) for more details and instructions on setting up an environment to build Robolectric.

Once you are able to build Robolectric, create a feature branch to make your changes:

Expand Down
6 changes: 3 additions & 3 deletions custom-test-runner.md → docs/custom-test-runner.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
title: Customizing the Test Runner
group: Customizing
order: 3
hide:
- footer
- toc
---

# Customizing the Test Runner
Expand Down
10 changes: 4 additions & 6 deletions device-configuration.md → docs/device-configuration.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
---
title: Device Configuration
group: User Guide
order: 3
toc: true
hide:
- footer
---

# Device Configuration

Robolectric makes it easy to simulate a variety of device configurations. In particular, the properties that make up the `android.content.res.Configuration` class can be specified at the test method, test class, package, or suite level, as described [here](/configuring/).
Robolectric makes it easy to simulate a variety of device configurations. In particular, the properties that make up the `android.content.res.Configuration` class can be specified at the test method, test class, package, or suite level, as described [here](configuring.md).

## Specifying Device Configuration
The Android device configuration can be specified using the `qualifiers` config property:
Expand All @@ -22,7 +20,7 @@ From version 3.6 on, Robolectric parses the `qualifiers` property according to t
For unspecified properties, Robolectric picks consistent values based on the properties that have been specified, or uses default values as follows:

| Property | Calculated value (if unspecified) | Default | Other rules |
|----
|-----|-----|-----|-----|
| MCC and MNC | None. | None | |
| Language, region, and script (locale) | None. | `en-rUS` | |
| Layout direction | The locale’s layout direction. | `ldltr` | |
Expand Down
15 changes: 7 additions & 8 deletions extending.md → docs/extending.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
---
title: Shadows
group: Contributing
order: 1
redirect_from:
- /custom-shadows/
hide:
- footer
---

# Shadows

Robolectric works by creating a runtime environment that includes the real Android framework code. This means when your tests or code under test calls into the Android framework you get a more realistic experience as for the most part the same code is executed as would be on a real device. There are limitations however:

1. Native code - Android native code cannot execute on your development machine.
2. Out of process calls - There are no Android system services running on your development machine.
3. Inadequate testing APIs - Android includes next to no APIs suitable for testing
Expand Down Expand Up @@ -113,7 +111,7 @@ Methods on your shadow class are able to call through to the Android OS code, us

## Custom Shadows

Robolectric is a work in progress and we rely, welcome and strongly encourage [contributions](https://github.com/robolectric/robolectric.github.io/blob/master/contributing.md) from the community for bug fixes and feature gaps. However, if you wish to modify shadow behaviour in a way that is not appropriate for sharing, or you can't wait for a new release to include a critical fix we do support custom shadows.
Robolectric is a work in progress and we rely, welcome and strongly encourage [contributions](contributing.md) from the community for bug fixes and feature gaps. However, if you wish to modify shadow behaviour in a way that is not appropriate for sharing, or you can't wait for a new release to include a critical fix we do support custom shadows.

### Writing a Custom Shadow

Expand Down Expand Up @@ -143,13 +141,14 @@ public class MyShadowBitmap {

Custom Shadows get hooked up to Robolectric using the `@Config` annotation on the test class or test method, using the `shadows` array attribute. To use the `MyShadowBitmap` class mentioned in the previous section, you would annotate the test in question with `@Config(shadows={MyShadowBitmap.class})`, and to include multiple custom shadows: `@Config(shadows={MyShadowBitmap.class, MyOtherCustomShadow.class})`. This causes Robolectric to recognize and use your custom shadow when executing code against the class you shadowed.

If you would like your custom shadows to be applied to all tests in your suite or a certain package you can configure shadows through the [robolectric.properties](https://github.com/robolectric/robolectric.github.io/blob/master/configuring.md) file.
If you would like your custom shadows to be applied to all tests in your suite or a certain package you can configure shadows through the [robolectric.properties](configuring.md) file.

Note, by default `Shadows.shadowOf()` method will not work with custom shadows. You can instead use `Shadow.extract()` and cast the return value to the custom Shadow class you implemented.

### Building a library of Custom Shadows.

If you find yourself building a library of custom shadows you should consider running Robolectric's shadow annoation processor on your library of shadows. This provides a number of benefits such as

1. Generating `shadowOf` methods for each of your shadows.
2. Generating a ServiceLoader so your custom shadows are automatically applied if found on the classpath
3. Invoking any `static` `@Resetter` methods on teardown to enable you to reset static state.
Expand Down Expand Up @@ -211,4 +210,4 @@ Rather than using shadows as glorified argument captors prefer writing a shadow
Robolectric provides a lot of power which requires responsible usage. Shadows are ideal for testing interaction with the Android framework as the framework doesn't support dependency injection and makes liberal use of static code. Before writing custom shadows for your own code, consider if you can't better refactor your code and use a popular mocking library such as Mockito.

### Support the community
Please please [contribute](https://github.com/robolectric/robolectric.github.io/blob/master/contributing.md) your enhancements for sharing with the community and reducing the bloat in your own codebase.
Please please [contribute](contributing.md) your enhancements for sharing with the community and reducing the bloat in your own codebase.
14 changes: 6 additions & 8 deletions getting-started.md → docs/getting-started.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
---
title: Getting Started
group: Setup
order: 1
toc: true
hide:
- footer
---

# Getting Started

Robolectric works best with Gradle or Bazel. If you are starting a new project, we would recommend Gradle first (since it is the build system of choice in Android Studio) and Bazel second. Both environments provide first class support for Robolectric. If you are using another build system see how to configure [other environments](/other-environments) or learn how to provide first class [build system integration](/build-system-integration) support for other environments.
Robolectric works best with Gradle or Bazel. If you are starting a new project, we would recommend Gradle first (since it is the build system of choice in Android Studio) and Bazel second. Both environments provide first class support for Robolectric. If you are using another build system see how to configure [other environments](other-environments.md) or learn how to provide first class [build system integration](build-system-integration.md) support for other environments.

## Building with Android Studio/Gradle

Expand All @@ -26,7 +24,7 @@ android {
dependencies {
testImplementation 'junit:junit:4.13.2'
testImplementation 'org.robolectric:robolectric:{{ site.robolectric.version.current | escape }}'
testImplementation 'org.robolectric:robolectric:{{ robolectric.version.current }}'
}
```

Expand Down Expand Up @@ -98,8 +96,8 @@ android_local_test(
## Other Environments

* [Buck](https://buckbuild.com/rule/robolectric_test.html)
* [Older Android Studio/Gradle Versions](/other-environments/#android-studio--gradle-agp--30)
* [Maven & Eclipse](/other-environments/#maven--eclipse)
* [Older Android Studio/Gradle Versions](other-environments.md#android-studio-gradle-agp-30)
* [Maven & Eclipse](other-environments.md#maven-eclipse)

## Sample Projects

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes
11 changes: 4 additions & 7 deletions index.md → docs/index.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
---
# You don't need to edit this file, it's empty on purpose.
# Edit theme's home layout instead if you wanna make some changes
# See: https://jekyllrb.com/docs/themes/#overriding-theme-defaults
# layout: home
front: true
hide:
- footer
- navigation
---

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.
Expand All @@ -13,7 +11,6 @@ Running tests on an Android emulator or device is slow! Building, deploying, and
```java
@RunWith(RobolectricTestRunner.class)
public class MyActivityTest {

@Test
public void clickingButton_shouldChangeMessage() {
try (ActivityController<MyActivity> controller = Robolectric.buildActivity(MyActivity.class)) {
Expand All @@ -26,7 +23,7 @@ public class MyActivityTest {
}
}
```
[» Getting Started...](/getting-started/)
[» Getting Started...](getting-started.md)

### Test APIs & Isolation

Expand Down
Loading

0 comments on commit ad00deb

Please sign in to comment.