When starting to learn Java, one of the first things you are taught is that a class consists of several things, among which are the ‘methods’. A method is nothing more than grouping of several code lines. Since tests are code, the same principle applies to writing your Java based tests. Especially if you are dealing with duplicate code (code you keep copy/pasting all across your test project).
So what would be the reasons for not wanting to duplicate your code, but instead grouping it into methods: Continue reading Better Test Code Principles: #1 Don’t copy/paste the code. Reuse it.