https://github.com/decision-driven-development/output-tracking
Java implementation of James Shore's output tracking method for Nullables and Testing without mocking
https://github.com/decision-driven-development/output-tracking
java nullables output-tracking testing-tools testing-without-mocks
Last synced: about 1 year ago
JSON representation
Java implementation of James Shore's output tracking method for Nullables and Testing without mocking
- Host: GitHub
- URL: https://github.com/decision-driven-development/output-tracking
- Owner: Decision-Driven-Development
- License: mit
- Created: 2025-05-06T05:19:40.000Z (about 1 year ago)
- Default Branch: master
- Last Pushed: 2025-05-06T06:06:05.000Z (about 1 year ago)
- Last Synced: 2025-05-06T06:46:24.060Z (about 1 year ago)
- Topics: java, nullables, output-tracking, testing-tools, testing-without-mocks
- Language: Java
- Homepage:
- Size: 10.7 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# Java Output Tracking for Testing without Mocks
Java implementation of James Shore's output tracking method for Nullables and
[Testing without mocks](https://www.jamesshore.com/v2/projects/nullables/testing-without-mocks)
approach.
## Description
`output-tracking` is a lightweight library designed to facilitate testing without relying on mocking
frameworks. It provides tools to track and verify outputs produced by testable components, enabling
clean and maintainable tests.
## Installation
To include `output-tracking` in your project, add the following dependency to your `pom.xml` if
you're using Maven:
```xml
com.example
output-tracking
1.0.0
```
For Gradle, add this to your `build.gradle`:
```gradle
implementation 'com.example:output-tracking:1.0.0'
```
## Usage
### Tracking Outputs
The library allows you to track outputs produced by your components. You can read the tests to get
an idea of how to use the library, but here's a simple example:
```java
import ewc.utilities.testableio.tracking.OutputListener;
import ewc.utilities.testableio.tracking.OutputTracker;
public class Example {
public static void main(String[] args) {
OutputListener listener = new OutputListener<>();
OutputTracker tracker = listener.trackOutput();
// Simulate producing outputs
listener.track("Hello");
listener.track("World");
// Retrieve tracked outputs
System.out.println(tracker.data()); // Output: [Hello, World]
// Clear tracked outputs
tracker.clear();
System.out.println(tracker.data()); // Output: []
}
}
```
### Stopping Tracking
You can stop tracking outputs and remove the tracker from the listener:
```java
OutputListener listener = new OutputListener<>();
OutputTracker tracker = listener.trackOutput();
public class Example {
public static void main(String[] args) {
listener.track("Test Output");
System.out.println(tracker.data()); // Output: [Test Output]
// Stop tracking
tracker.stopTracking();
System.out.println(listener.trackers().isEmpty()); // Output: true
listener.track("Another Output"); // This won't be tracked anywhere
}
}
```
## Features
- Enable testable components to produce some output describing their state and behavior. Think
of it as a logging mechanism that stores any kind of objects, so you can then test the sequence of
logged events and the data they contain.
- Retrieve and clear tracked outputs.
- Manage multiple trackers with a single listener.
## License
This project is licensed under the MIT License. See the LICENSE file for details.