An open API service indexing awesome lists of open source software.

https://github.com/foiovituh/uva-tester

A minimalist Java library for effortless unit test execution 🍇
https://github.com/foiovituh/uva-tester

java java-annotations java-library maven testing unit-testing unit-tests uva uva-tester uvatester

Last synced: about 2 months ago
JSON representation

A minimalist Java library for effortless unit test execution 🍇

Awesome Lists containing this project

README

          

# UVATester 🍇
![GitHub License](https://img.shields.io/github/license/foiovituh/uva-tester)

![logo](https://github.com/foiovituh/uva-tester/assets/68431603/869607ca-68bc-4630-9a9a-4d4a0794dd82)

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 📝
- [UVATester 🍇](#uvatester-)
- [Summary 📝](#summary-)
- [How does it work? 💡](#how-does-it-work-)
- [Requirements 🔗](#requirements-)
- [Quick usage guide 📚](#quick-usage-guide-)
- [Installation:](#installation)
- [Mapping process:](#mapping-process)
- [Execution:](#execution)
- [Assertor:](#assertor)
- [Future plans 📌](#future-plans-)
- [Do you want help me? 👥](#do-you-want-help-me-)
- [License 🏳️](#license-️)

## 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`:

```xml


jitpack.io
https://jitpack.io


com.github.foiovituh
uva-tester
v1.0-SNAPSHOT

```

---

#### 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:

```java
@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:
```java
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:
```java
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`](LICENSE) for more information.