21.What are JUnit classes? List some of them.JUnit classes are important classes which are used in writing and testing JUnits. Some of the important classes are−
22.What are annotations and how are they useful in JUnit?Annotations are like meta-tags that you can add to you code and apply them to methods or in class. The annotation in JUnit gives us information about test methods, which methods are going to run before & after test methods, which methods run before & after all the methods, which methods or class will be ignore during execution. 23.How will you run JUnit from command window?Follow the steps below−
java org.junit.runner.JUnitCore
24.What is the purpose of org.junit.Assert class?This class provides a set of assertion methods useful for writing tests. Only failed assertions are recorded. 25.What is the purpose of org.junit.TestResult class?A TestResult collects the results of executing a test case. It is an instance of the Collecting Parameter pattern. The test framework distinguishes between failures and errors. A failure is anticipated and checked for with assertions. Errors are unanticipated problems like an ArrayIndexOutOfBoundsException. 26.What is the purpose of org.junit.TestSuite class?A TestSuite is a Composite of Tests. It runs a collection of test cases. 27.What is the purpose of @Test annotation in JUnit?The Test annotation tells JUnit that the public void method to which it is attached can be run as a test case. 28.What is the purpose of @Before annotation in JUnit?Several tests need similar objects created before they can run. Annotating a public void method with @Before causes that method to be run before each Test method. 29.What is the purpose of @After annotation in JUnit?If you allocate external resources in a Before method you need to release them after the test runs. Annotating a public void method with @After causes that method to be run after the Test method. 30.What is the purpose of @BeforeClass annotation in JUnit?Annotating a public static void method with @BeforeClass causes it to be run once before any of the test methods in the class. 31.What is the purpose of @AfterClass annotation in JUnit?This will perform the method after all tests have finished. This can be used to perform clean-up activities. 32.What is @Ignore annotation and how is this useful?Following are some of the usefulness of @Ignore annotation − 33.Explain the execution procedure of the JUint test API methods?Following is how the JUnit execution procedure works−
34.What is the purpose of org.junit.JUnitCore class?The test cases are executed using JUnitCore class. JUnitCore is a facade for running tests. It supports running JUnit 4 tests, JUnit 3.8.x tests, and mixtures. 35.How to simulate timeout situation in JUnit?Junit provides a handy option of Timeout. If a test case takes more time than specified number of milliseconds then Junit will automatically mark it as failed. The timeout parameter is used along with @Test annotation. 36.How can you use JUnit to test that the code throws desired exception?JUnit provides a option of tracing the Exception handling of code. You can test if a code throws desired exception or not. The expected parameter is used along with @Test annotation as follows− @Testexpected 37.What are Parameterized tests?Junit 4 has introduced a new feature Parameterized tests.Parameterized tests allow developer to run the same test over and over again using different values. 38.How to create Parameterized tests?There are five steps, that you need to follow to create Parameterized tests−
39.How do you use test fixtures?Fixtures is a fixed state of a set of objects used as a baseline for running tests. The purpose of a test fixture is to ensure that there is a well known and fixed environment in which tests are run so that results are repeatable. It includes−
40.How to compile a JUnit Test Class?Compiling a JUnit test class is like compiling any other Java classes. The only thing you need watch out is that the JUnit JAR file must be included in the classpath. |