title: How can I access the contents of a StatefulWidget's State during a unit test?
body: <p>I have a StatefulWidget (call it <code>MyWidget</code>) whose State (<code>MyWidgetState</code>) has a field <code>myData</code> which is initialized during <code>initState()</code> as follows:</p>
  
  <pre><code>void initState() {
      super.initState();
      myData = new myData(config.someField.getId());
  }
  </code></pre>
  
  <p>When the user presses a button, myData is added to or removed from a global list.</p>
  
  <p>I'm trying to write a unit test to test this behavior but I don't know how to get access to a MyWidgetState.  I tried including this in the setup():</p>
  
  <pre><code>widget = MyWidget();
  widgetState = widget.createState(); 
  widgetState.init();
  </code></pre>
  
  <p>but it crashes every time when it tries to initState(), complaining that "someField was called on null".  That's fine. I was probably cheating by trying to do it that way and I ought to do something with a WidgetBuilder or launch an application using MyWidget and then find MyWidget in the tree once it's properly instantiated. </p>
  
  <p>If I do all of that, once I do how can I access that MyWidget's MyWidgetState to get a copy of myData and compare it to the global list?  </p>