A Java library that uses annotations and reflection to discover and execute custom unit tests.
Note: UVATester is my own implementation of a unit testing library, built from scratch as a study project to explore Java annotations and reflection. Although fully functional, it is intended for educational purposes rather than as a production-ready alternative to established frameworks such as JUnit.
Add the JitPack repository and the dependency to your pom.xml:
<repositories> <repository> <id>jitpack.io</id> <url>https://jitpack.io</url> </repository> </repositories> <dependencies> <dependency> <groupId>com.github.foiovituh</groupId> <artifactId>uva-tester</artifactId> <version>v1.0-SNAPSHOT</version> </dependency> </dependencies>
Required:
- Java
- Maven
Optional:
- JitPack
UVATester loads a test class using Java reflection and verifies that it is annotated with @TestClass.
It then discovers every method annotated with @TestMethod that is public, static, returns void, and accepts no arguments. Each compatible method is invoked automatically.
If the test class is invalid or a test throws an exception during execution, UVATester logs the error and terminates the execution.
Annotate the class with @TestClass and every test method with @TestMethod.
Each test method must:
- be annotated with
@TestMethod - be
public - be
static - return
void - receive no arguments
Example:
@TestClass public class CalculatorTests { @TestMethod public static void sumShouldReturnFour() { int result = 2 + 2; Feedback.showResult( "sumShouldReturnFour", result == 4 ? "PASS" : "FAIL" ); } }
Instantiate UVATester with the fully qualified name of the test class and call run().
public class Main { public static void main(String[] args) { new UVATester( CalculatorTests.class.getName() ).run(); } }
Example output:
sumShouldReturnFour => PASS
The Assertor class provides reusable validation methods that can simplify assertions inside your test methods.
Example:
boolean validAge = Assertor.isWithinRange(age, 18, 65); Feedback.showResult( "validAge", validAge ? "PASS" : "FAIL" );
Current limitations include:
- Test methods must be
public static voidand receive no arguments. - Tests are executed sequentially.
- Execution stops immediately if a test throws an exception.
- Add more assertion methods
- Continue executing tests after failures
If you like this project or find it useful, please give it a star! It helps increase its visibility and supports future development.
Distributed under the MIT License. See LICENSE for more information.
