Events
In situations where direct testing through APIs, database queries, or dependencies isn't possible, validation is performed by manually reviewing logs to confirm the occurrence of specific logic.
For such cases, utilize Tesmon's event functionality by emitting an HTTP event, and set up your test to expect and respond to this event. This allows you to build an end-to-end testing strategy, and even validate logic that may not be accessible through APIs or databases.
Publishing events
Sources
Publish an Event from any of the following sources:
- iOS/Android/Web Apps
- Microservices
- Batch Processing Jobs
- Streaming or Data Pipelines
Methods
Tesmon offers multiple ways to publish events:
- curl
- Logs
- Java / Kotlin / Android
- Javascript
- Python
- iOS
curl -X POST 'https://api.tesmon.io/v1/environments/<environment_id>/events' \
-H 'Content-Type: application/json' \
-H 'Authorization: ApiToken <api_token>' \
-d '{ "key": "<EVENT_KEY>", "value": "<EVENT_BODY_IN_JSON>" }'
Using Application Logging
Using logs to publish events is a simple and effective approach. It requires configuring your logging infrastructure to emit logs in a specific format.
To publish events via logging, you need to define an appender that sends logs to Tesmon's Test Run Engine (TRE). Here is an example configuration for Log4j2 in XML format:
Example log4j2 setup
<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="WARN">
<Appenders>
<Http name="tesmonEvents" url="<Tesmon_Test_Run_Engine_URL>/v1/events" method="POST" ignoreExceptions="false">
<JsonLayout compact="true" eventEol="true" />
</Http>
</Appenders>
<Loggers>
<Logger name="tesmonEventLogger" level="INFO" additivity="false">
<AppenderRef ref="tesmonEvents" />
</Logger>
<Root level="ERROR">
<AppenderRef ref="tesmonEvents" />
</Root>
</Loggers>
</Configuration>
In this example, we define an appender named "tesmonEvents" that sends HTTP POST requests to Tesmon's TRE endpoint. The JsonLayout specifies that logs should be formatted as JSON.
Once you have defined your appender, you can use your logging framework to emit events. Here is an example in Java that logs an event using the configured "tesmonEventLogger":
Usage
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
private static final Logger LOGGER = LoggerFactory.getLogger("tesmonEventLogger");
// Create the event JSON
String eventJson = "{ \"key\": \"b074b045-b611-490d-b4ed-af7ba56ad777\", \"createdAt\": 1619025480000, \"value\": { \"sampleKey\": \"sampleValue\", \"anotherKey\": 123 } }";
// Log the event as JSON
LOGGER.info(eventJson);
The package is available on Maven Central.
Usage
TesmonEventClient tesmonEventClient = new DefaultTesmonEventClient("<environment_id>", "<api_token>");
tesmonEventClient.send_event(<key>, <eventBody>);
Dependency
- Maven
- Gradle
<dependencies>
<dependency>
<groupId>io.tesmon</groupId>
<artifactId>tesmon-java-sdk</artifactId>
<version>X.X.X</version>
</dependency>
</dependencies>
dependencies {
implementation 'io.tesmon:tesmon-java-sdk:X.X.X'
}
Coming soon
Coming soon
Coming soon