title: How do I test an assertion?
body: <p>I found out how you can test an exception or error: <a href="https://stackoverflow.com/a/54241438/6509751">https://stackoverflow.com/a/54241438/6509751</a></p>
  
  <p>But how do I test that the following <code>assert</code> works correctly?</p>
  
  <pre class="lang-dart prettyprint-override"><code>void cannotBeNull(dynamic param) {
    assert(param != null);
  }
  </code></pre>
  
  <p>I tried the following, but it does not work. The assertion is simply printed out and the test fails:</p>
  
  <pre class="lang-dart prettyprint-override"><code>void main() {
    test('cannoBeNull assertion', () {
      expect(cannotBeNull(null), throwsA(const TypeMatcher&lt;AssertionError&gt;()));
    });
  }
  </code></pre>