Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

do assertations exist in both JAVA and JUnit?

I am looking at one of the question that is posted long back by x person.

Ex: assertEquals(driver.getPageSource().contains("sometext"), true);

(or) assertEquals(boolean , boolean);

If the above method exists I love to use it. I looked around JUnit API and its methods and there is no such method .

1) If it exists can someone post the relevant link, please ?

2) do assertations exist in JAVA default classes? (I know they are there in JUNIT)

like image 553
MKod Avatar asked Jan 31 '26 18:01

MKod


2 Answers

Why not use assertTrue(driver.getPageSource().contains("sometext"));?

like image 88
Daniel Kaplan Avatar answered Feb 02 '26 08:02

Daniel Kaplan


The assertEquals methods are in JUnit, specifically in the org.junit.Assert class:

You typically import them with a static import statement like this:

import static org.junit.Assert.*;

assert on its own is part of core Java, it provides a way to add sanity checks that get run while you are debugging, but which get ignored (and therefore don't add any overhead) in production code.

assert(something==somethingElse);
like image 28
mikera Avatar answered Feb 02 '26 10:02

mikera



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!