@Test
  public void testPluginDumpsRecursively() throws Throwable {
    ViewHelpers.setupView(mView).setExactHeightPx(1000).setExactWidthPx(20000).layout();

    LayoutHierarchyDumper dumper =
        LayoutHierarchyDumper.createWith(
            Collections.<HierarchyPlugin>emptyList(),
            Collections.singletonList(mTextAttributePlugin));

    JSONObject node = dumper.dumpHierarchy(mView);

    List<String> allText = new ArrayList<>();
    Queue<JSONObject> toCheck = new ArrayDeque<>();
    toCheck.offer(node);
    while (!toCheck.isEmpty()) {
      JSONObject object = toCheck.poll();
      String maybeText = object.optString("Text:text");
      if (!TextUtils.isEmpty(maybeText)) {
        allText.add(maybeText);
      }
      JSONArray children = object.optJSONArray(BaseViewHierarchyPlugin.KEY_CHILDREN);
      if (children == null) {
        continue;
      }
      for (int i = 0; i < children.length(); ++i) {
        toCheck.offer(children.getJSONObject(i));
      }
    }

    List<String> expected = new ArrayList<>();
    expected.add("foobar");
    expected.add("foobar2");
    expected.add("foobar3");
    expected.add("foobar4");

    assertEquals(expected, allText);
  }
Utility class to make inspecting a serialized hierarchy easier
core/src/androidTest/java/com/facebook/testing/screenshot/layouthierarchy/LayoutHierarchyDumperTest.java