I had assumed that JUnit found tests (inside classes derived from junit.framework.TestCase) by looking for methods annotated with @Test. However, I've included a test from http://256stuff.com/sources/jenkins_hash_java/JenkinsHashTest.java in a project. The structure of the code is as follows:
import junit.framework.TestCase;
public class JenkinsHashTest extends TestCase {
public void testHashes() {
...//this code is run
}
}
I have confirmed that the test method testHashes() is run despite not being annotated with @Test. In case it's relevant, I'm invoking all of this via gradle test.
You can refer to this Junit 3 vs Junit 4 Comparison:
Basically, in JUnit 3 you need to extend junit.framework.TestCase. All test cases need to follow the testXXX pattern.
JUnit 4 removes that restrictions. Any public classes with a zero-argument public constructor can act as a test class. Any methods which need consider as a test method should be annotated with the @Test annotation.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With