# Testing randomness

DevFeed: [Testing randomness](<https://devfeed.tech/articles/testing-randomness-27295.md>)

Original publisher: [Read original article](<https://blog.pchudzik.com/201803/testing-randomness/>)

Published: 2018-03-20T00:00:00Z

Content type: tutorial

Language: en

Sources: [Paweł Chudzik](<https://devfeed.tech/sources/pawe-chudzik.md>)

Topics: [Testing](<https://devfeed.tech/topics/testing.md>), [Dependency injection](<https://devfeed.tech/topics/dependency-injection.md>), [business logic](<https://devfeed.tech/topics/business-logic.md>), [Java](<https://devfeed.tech/topics/java.md>)

Tags: [blog](<https://devfeed.tech/tags/blog.md>), [business-logic](<https://devfeed.tech/tags/business-logic.md>), [dependency-injection](<https://devfeed.tech/tags/dependency-injection.md>), [java](<https://devfeed.tech/tags/java.md>), [test](<https://devfeed.tech/tags/test.md>), [testing](<https://devfeed.tech/tags/testing.md>)

## AI overview

This tutorial explains how to test time-dependent and random behavior by injecting the changing data source from outside and replacing it with fixed values during tests. It discusses dependency injection, Java clocks, random calculations, and method-parameter implementations for deterministic tests.

## Source excerpt

While deep diving into the code I very often see people struggle when testing random changing/things. There is a really simple solution for this and in this blog post, I'm going to show you "one simple trick" that will fix this problem. Read more