Junit provides four annotations Before After BeforeClass Aft

Junit provides four annotations @Before, @After, @BeforeClass, @AfterClass. Explain how you can use them testing OO applications (give examples)

Solution

@Before : this is used to execute set of preconditions before executing a test. For an example consider that there is a need to open some application, then create a user before executing a test. So @Before annotation can be used to gain this approach. Also methods whiich consists of @Before annotationn always execute before executing everu test within the class.

@Aftter : here when this annootaton used methods only get executed after every test have been executed.If it is needed to reset some variables after execution of every test then this annotation can be used with a method that has the needed code.

@BeforeClass :use when JUnit Test Case class contains lot oof tests which all together need a method which set up a precondition. Also that needs to be executed before executing the test case class.

@AfterClass : use whe to execute a method that needs to be executed after executing all the tests in a JUnit Test Case class.

Junit provides four annotations @Before, @After, @BeforeClass, @AfterClass. Explain how you can use them testing OO applications (give examples)Solution@Before

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site