When should I use Debug.Assert()?

In Debugging Microsoft .NET 2.0 Applications John Robbins has a big section on assertions. His main points are: Assert liberally. You can never have too many assertions. Assertions don’t replace exceptions. Exceptions cover the things your code demands; assertions cover the things it assumes. A well-written assertion can tell you not just what happened and … Read more

How can i use soft assertion in Cypress

The soft assertion concept is pretty cool, and you can add it with minimal implementation to Cypress const jsonAssertion = require(“soft-assert”) it(‘asserts several times and only fails at the end’, () => { jsonAssertion.softAssert(10, 12, “expected actual mismatch”); // some more assertions, not causing a failure jsonAssertion.softAssertAll(); // Now fail the test if above fails … Read more

CollectionAssert in jUnit?

Using JUnit 4.4 you can use assertThat() together with the Hamcrest code (don’t worry, it’s shipped with JUnit, no need for an extra .jar) to produce complex self-describing asserts including ones that operate on collections: import static org.junit.Assert.assertThat; import static org.junit.matchers.JUnitMatchers.*; import static org.hamcrest.CoreMatchers.*; List<String> l = Arrays.asList(“foo”, “bar”); assertThat(l, hasItems(“foo”, “bar”)); assertThat(l, not(hasItem((String) null))); … Read more

How to continue execution when Assertion is failed

I suggest you to use soft assertions, which are provided in TestNg natively package automation.tests; import org.testng.asserts.Assertion; import org.testng.asserts.SoftAssert; public class MyTest { private Assertion hardAssert = new Assertion(); private SoftAssert softAssert = new SoftAssert(); } @Test public void testForSoftAssertionFailure() { softAssert.assertTrue(false); softAssert.assertEquals(1, 2); softAssert.assertAll(); } Source: http://rameshbaskar.wordpress.com/2013/09/11/soft-assertions-using-testng/

AssertEquals 2 Lists ignore order

As you mention that you use Hamcrest, So I would pick one of the collection Matchers import static org.hamcrest.collection.IsIterableContainingInAnyOrder.containsInAnyOrder; import static org.junit.Assert.assertThat; public class CompareListTest { @Test public void compareList() { List<String> expected = Arrays.asList(“String A”, “String B”); List<String> actual = Arrays.asList(“String B”, “String A”); assertThat(“List equality without order”, actual, containsInAnyOrder(expected.toArray())); } }