Skip to content

foiovituh/uva-tester

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

9 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

UVATester πŸ‡

GitHub License

logo

A minimalist Java library for effortless unit test execution. Although functional, my main goal was to put my studies on annotation and reflection in Java into practice. It was also a fun challenge to develop a test library from scratch and without references.

Summary πŸ“

How does it work? πŸ’‘

UVATester's main process can be summarized as follows:

  • Receiving the name of a test class, loading it dynamically via reflection.
  • Checking that the class has the @TestClass annotation.
  • Invoking each method in the class that has the @TestMethod annotation and follows certain criteria (for more details, see the "Mapping process" section).
  • If any problems occur during the execution of the tests, the details of the error will be logged and then the UVATester will be terminated.

Requirements πŸ”—

Mandatory:

  • Java 17+
  • Maven 4.0.0+

Optional:

  • JitPack

Quick usage guide πŸ“š

Installation:

Add and download the following dependencies 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>

Mapping process:

Annotate your test class with @TestClass, and annotate your test methods with @TestMethod. The test methods should be static, return void, and have no arguments. For example:

@TestClass
public class ShoppingTrolleyTest {
    @TestMethod
    public static void testEmptyShoppingTrolleyGuardingReturnsTrue() {
    	final var shoppingTrolley = new ShoppingTrolley();
    	
    	final var testName = "testEmptyShoppingTrolleyGuardingReturnsTrue";
        final var testResult = shoppingTrolley.guardShoppingTrolley()
        		&& Assertor.isNullOrEmpty(shoppingTrolley.getItems())
        			? "pass"
        			: "failed";
        
        Feedback.showResult(testName, testResult);
    }
}

Execution:

Instantiate a UVATester object using the test class name and invoke its run() method to execute all defined tests:

public class ShoppingTrolleyTestExecutor {
    public static void main(String[] args) {
        final var shoppingTrolleyTests = new UVATester(
                ShoppingTrolleyTest.class.getName()
        );
        
        shoppingTrolleyTests.run();
    }
}

Assertor:

You can also use assertion methods that can be useful when developing tests. They are available in the class: com.github.foiovituh.uvatester.utils.Assertor. For example, the method:

public static boolean isWithinRange(int value, int min, int max) {
    return value >= min && value <= max;
}

Future plans πŸ“Œ

  • Add more methods to the Assertor class
  • Make it optional to close tests if one fails

Do you want help me? πŸ‘₯

If you have any ideas or wish to contribute to the project, contact me on X (@ohtoaki) or send me a pull request :)

License πŸ“„

Distributed under the MIT License. See LICENSE for more information.

About

A minimalist Java library for effortless unit test execution πŸ‡

Topics

Resources

License

Code of conduct

Security policy

Stars

Watchers

Forks

Packages

No packages published

Languages