NavTutorial← All tutorials

Assertion & Matcher Explorer

Every common assertion, side by side across TestNG, JUnit 5, Playwright's expect and Chai. Type to filter — find the matcher you know in one framework and read off its equivalent in the others.

AssertionTestNGJUnit 5PlaywrightChai / Cypress
Equality assertEquals(exp, act) assertEquals(exp, act) expect(act).toBe(exp) expect(act).to.equal(exp)
Deep equality assertEquals(list1, list2) assertIterableEquals(a, b) expect(act).toEqual(exp) expect(act).to.deep.equal(exp)
True assertTrue(cond) assertTrue(cond) expect(cond).toBeTruthy() expect(cond).to.be.true
False assertFalse(cond) assertFalse(cond) expect(cond).toBeFalsy() expect(cond).to.be.false
Null assertNull(obj) assertNull(obj) expect(obj).toBeNull() expect(obj).to.be.null
Not null assertNotNull(obj) assertNotNull(obj) expect(obj).not.toBeNull() expect(obj).to.not.be.null
Contains (string) assertTrue(s.contains(x)) assertTrue(s.contains(x)) expect(s).toContain(x) expect(s).to.include(x)
Element visible — — await expect(loc).toBeVisible() —
Element has text assertEquals(x, el.getText()) — await expect(loc).toHaveText(x) cy.get(sel).should("have.text", x)
Element enabled assertTrue(el.isEnabled()) — await expect(loc).toBeEnabled() cy.get(sel).should("be.enabled")
Count / length assertEquals(n, list.size()) — await expect(loc).toHaveCount(n) cy.get(sel).should("have.length", n)
Throws assertThrows(E.class, () -> ...) assertThrows(E.class, exec) expect(fn).toThrow() expect(fn).to.throw()
Greater than assertTrue(a > b) assertTrue(a > b) expect(a).toBeGreaterThan(b) expect(a).to.be.greaterThan(b)

No assertion matches that search.

Choosing the right assertion

Assert on the most specific condition you can. For UI checks, prefer web-first assertions that auto-retry (Playwright's toBeVisible, Cypress's should) over reading a value and comparing it yourself — they wait for the condition and remove a whole class of flakiness. For data checks, use deep equality for collections and objects rather than reference equality.

JUnit 5 vs TestNG

The matchers are close cousins: both offer assertEquals, assertTrue, assertThrows. JUnit 5 puts the expected value first and adds assertAll for grouped assertions and assertIterableEquals for collections; TestNG's assertEquals is overloaded for many types and integrates tightly with its data-provider model.

Playwright expect vs Chai

Playwright's expect has two flavours: generic value matchers and auto-retrying locator assertions (the await expect(locator).toBeVisible() form). Chai — used by Cypress and Mocha — reads as fluent English (expect(x).to.equal(y)) and Cypress layers retry-ability on top through .should().

Built by NavTutorial · A free tool for QA automation engineers.