Testing

Developer tools are only used if they work. We have built APIs to test plugins.

Writing tests

Desktop plugins

Flipper uses Jest as unit testing framework.

Writing unit tests for Flipper Desktop plugins is covered in detail in the tutorial.

The flipper-plugin package provide several test utilities to make testing more convenient.

Client plugins

Start by creating your first test file in this directory `MyFlipperPluginTest.java`. In the test method body we create our plugin which we want to test as well as a `FlipperConnectionMock`. In this contrived example we simply assert that our plugin's connected status is what we expect.
@RunWith(RobolectricTestRunner.class)
public class MyFlipperPluginTest {
@Test
public void myTest() {
final MyFlipperPlugin plugin = new MyFlipperPlugin();
final FlipperConnectionMock connection = new FlipperConnectionMock();
plugin.onConnect(connection);
assertThat(plugin.connected(), equalTo(true));
}
}

There are two mock classes that are used to construct tests FlipperConnectionMock and FlipperResponderMock. Together these can be used to write very powerful tests to verify the end to end behavior of your plugin. For example we can test if for a given incoming message our plugin responds as we expect.

@Test
public void myTest() {
final MyFlipperPlugin plugin = new MyFlipperPlugin();
final FlipperConnectionMock connection = new FlipperConnectionMock();
final FlipperResponderMock responder = new FlipperResponderMock();
plugin.onConnect(connection);
final FlipperObject params = new FlipperObject.Builder()
.put("phrase", "flipper")
.build();
connection.receivers.get("myMethod").onReceive(params, responder);
assertThat(responder.successes, hasItem(
new FlipperObject.Builder()
.put("phrase", "ranos")
.build()));
}

Running (Flipper) tests

Flipper Desktop

Run yarn jest or yarn jest --watch in the desktop directory of your Flipper checkout.

Flipper SDK

Android (Java)

Gradle:

In the root directory of the checkout:

./gradlew android:test

React Native

See testing React Native.