thisisdude
thisisdude

Reputation: 576

How to check whether the values are in Float using jUnit assertion?

I am trying to automate an API. In response, I am getting float value for one of the keys. The value is dynamic so the only thing I want to assert is to check whether the value is a float number or not. How can we assert that via jUnit5 library?

Upvotes: 0

Views: 200

Answers (1)

T A
T A

Reputation: 1756

You could just try to read the value as a float using Float.valueOf(), if it can't be interpreted as a float the function will throw an exception and the test will fail. Something like this:

@Test
public void isFloat() {
    // this will throw an exception
    Float.valueOf("definitely_not_a_float");
}

Upvotes: 1

Related Questions