Issue
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?
Solution
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");
}
Answered By - T A
Answer Checked By - David Goodson (JavaFixing Volunteer)