JUnit Assume Class

Assume class basically a class which contains those methods which will first check the conditions on which the test will be meaning full. If that condition doesn’t meet then all the tests will be skipped.


This class can also be used to ignore test cases without the use of @Ignore annotation. Let’s see an example of uses of Assume class in your test class. Assume class has many methods lets have a look at some important methods.


1. assumeTrue(boolean) – This method accepts only boolean type argument. If the argument is false then it will halt the execution.

Let’s take an example suppose we want to implement our Test classes like if the DB connection is open then execute the TestClass otherwise skip all tests.

In the below example we have implemented the checkDB() method which will return false if the DB connection is closed and true if DB is up. Here we explicitly returning the false to check the functionality of assumeTrue() method.

Skip Test in JUnit


In the above test result, you can see both of the Test Method has been skipped because the argument in assumeTrue() was false.

It’s very useful practice to prepare an effective and good test script.


2. assumeNoException() – This one is another useful method in Assume class. You can use it if your system is real time and there may be chances to occur exceptions randomly. If any exception occurs then this will halt the execution. We can understand this with the following example.

Skip Test in JUnit


So we have seen assume the class is very useful for us. As we can put the conditions on the another way use can say we can verify the Test prerequisite with the help of Assume class. If prerequisite is available then execute the test cases otherwise don’t waste the time in execution and increase the failure rate.


Selenium Tutorial:

If you liked this video, then please subscribe to our YouTube Channel for more video tutorials.

0 Comment

Leave a Reply