Welcome to Software Development on Codidact!
Will you help us build our independent community of developers helping developers? We're small and trying to grow. We welcome questions about all aspects of software development, from design to code to QA and more. Got questions? Got answers? Got code you'd like someone to review? Please join us.
Post History
It's not clear from the question if the requirement is based on lines or statements. If what you care about is lines of code, you can put all three statements on one line. This doesn't do much for...
Answer
#1: Initial revision
It's not clear from the question if the requirement is based on *lines* or *statements*. If what you care about is lines of code, you can put all three statements on one line. This doesn't do much for readability, but then playing Code Golf rarely does. ``` void test() { Foo foo = new Foo(); foo.setX(42); assertEquals(13, bar.fun(foo).getY(), "Test failed because blabla"); } ``` If the requirement is for a single _statement_, then I don't see any way to achieve this without either writing a wrapper or changing the code under test. `assertEquals()` requires two values to compare, `setX()` does not return a value so either you need to change it so that it does, or put it behind some other function that will (directly or indirectly) return the value you are going to assert. My own suggestion would be to give up on the goal of "avoiding the need for scrolling". Packing source code into fewer lines will not increase the quality or readability of your code, and even if you succeed in making every test a single line, a requirement to avoid scrolling will still limit the number of tests you can have, which potentially _decreases_ code quality by reducing test coverage. But of course it's your choice how to style your code.