Code Monkey home page Code Monkey logo

Comments (2)

skinny85 avatar skinny85 commented on June 18, 2024

The reason I'm not in love with this feature is that I never liked the JUnit's expect attribute. In my opinion, the tests are less readable with it, and a lot more fragile (I've often seen tests that passed, but the actual Exception was not thrown from the line that the author intended, and so they were in fact 'false positives').

As long as Specnaz doesn't have this feature, it forces people to look for alternatives - which is great, because a lot of alternatives exist, and they are all better than JUnit's expect:

  • If you're using AssertJ for assertions, you have the assertThatThrownBy method for that exact scenario.
  • There is the CatchException library, tailor-built for this purpose.
  • Probably many others that I'm forgetting right now.

Design-wise, I don't see a problem with this feature. I would probably make the API look something like:

it.shoudThrow(IllegalArgumentException.class, "when called with a null argument", () -> {
    // the test name will be: "should throw IllegalArgumentException when called with a null argument"
    // ...
});

The perfect API would probably be:

it.shouldThrow<IllegalArgumentException>("when called with a null argument", () -> {
    // ...
});

..but I'm not sure that's possible with Java. I do know that KotlinTest does something like this, so perhaps that will be the API in the Kotlin version.

The only question is: do we want to do this, or do we rather skip this, forcing people to look for (better) alternatives?

from specnaz.

skinny85 avatar skinny85 commented on June 18, 2024

Fixed in 1.1 - resolving.

from specnaz.

Related Issues (10)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.