home.social

#assertions — Public Fediverse posts

Live and recent posts from across the Fediverse tagged #assertions, aggregated by home.social.

  1. One of the many good uses of assertions is to catch cases that Should Never Happen.
    The textbook example is the last branch of a multi-way conditional statement where one of the conditions before the final "else" must always be true.

    Another, where there must always be an element to be found:
    »    for each x in ...
    »    »    if x satisfies ...
    »    »    »    return x
    »    assert false

    #Assertions
    #ComputerProgramming
    #ProgramVerification

  2. If you have many assertions, you can also use the SoftAssertions to test all the assertions and give all the results at once.

    Read more 👉 lttr.ai/ATQTo

    #test #unitest #unitTest #testing #AssertJ #assertions #code #developer

  3. Throwing an exception when a business rule is invalid is very common, but do you know that it is very easy to create a test for it?

    Read more 👉 lttr.ai/AYtk5

    #test #unitest #unitTest #testing #AssertJ #assertions #code #developer

  4. If you're serious about #objectOriented programming, try to use #DesignByContract to the fullest extent your language supports it. Your future debugging self will thank you. At the very least, liberally use #assertions throughout your code to state what should be true at any given point in your code.

    en.wikipedia.org/wiki/Design_b

    #dbc #SoftwareEngineering