I often hear that a test should contain only one assertion (Disregarding testing attributes of a class) and where the whole pre-conditions for the test should be setup before the assertion.
In our application we have many tests where a user of the application logs in, performs some actions, then the state of the application is asserted, then the user does another thing etc and another assertion is validated. Another test might then only differ in some action taken during the test. For example (Pseudo code)
Test 1:
user = new User()
assertThat(user).is(created)
products = user.buyProducts(2 items)
assertThat(product.length, is(2))
Test 2:
user = new User()
assertThat(user).is(created)
product = user.buyProduct()
assertThat(product, is(notNullValue()))
This leads to tests which are sometimes extremely long (sometimes 50-100 lines, not counting helper methods) and often only differ in one our two statements. Unfortunately, the different statements are often not only variable replacements, so that we cannot use dynamic testing like with Junit5.
Is there another, better way to create the tests? Unfortunately most of our application's tests are setup like this. I also think it might be too much boilerplate to put all these setups into different setup methods and creating test classes which basically stop right in the middle (e.g. after asserting that the user is created), and then creating another test class which only asserts that the product is bought.