Search Interview Questions | More than 3000 questions in repository. There are more than 900 unanswered questions. Click here and help us by providing the answer. Have a video suggestion. Click Correct / Improve and please let us know. |
|
| |||||||||||
JUnit - Interview Questions and Answers for 'Junit' - 28 question(s) found - Order By Newest | |||||||||||
| |||||||||||
Ans. A JUnit Runner is a class that extends JUnit’s abstract Runner class and it is responsible for running JUnit tests. | |||||||||||
Help us improve. Please let us know the company, where you were asked this question : | |||||||||||
Like Discuss Correct / Improve   Asked in 1 Companies | |||||||||||
Ans. It helps in doing end to end Integration Testing | |||||||||||
Help us improve. Please let us know the company, where you were asked this question : | |||||||||||
Like Discuss Correct / Improve  mocking frameworks   mockito   unit testing   junits | |||||||||||
| |||||||||||
Ans. Using annotation Test with the argument as expected exception. @Test (expected = Exception.class) | |||||||||||
Help us improve. Please let us know the company, where you were asked this question : | |||||||||||
Like Discuss Correct / Improve  junit   junit annotations | |||||||||||
| |||||||||||
Ans. We can remove @Test from the respective test so as to avoid its execution. Alternatively we can put @Ignore annotation on the Junit file if we want to ignore all tests in a particular file. | |||||||||||
Help us improve. Please let us know the company, where you were asked this question : | |||||||||||
Like Discuss Correct / Improve  junit   @test   @ignore   unit tests   unit testing   testing | |||||||||||
| |||||||||||
Ans. We can either increase their visibility and mark them with annotation @VisibleForTesting or can use reflection to individually test those methods. | |||||||||||
Help us improve. Please let us know the company, where you were asked this question : | |||||||||||
Like Discuss Correct / Improve  junit   reflection api   @visiblefortesting   white box tester | |||||||||||
| |||||||||||
Ans. Initialize required objects for working with mocks and tested method Set the mock behaviour on dependent objects Execute the tested method Perform assertions Verify if a method is invoked or not | |||||||||||
Help us improve. Please let us know the company, where you were asked this question : | |||||||||||
Like Discuss Correct / Improve  junit   mocking frameworks   mock   unit testing   java   white box testing  Mockito | |||||||||||
| |||||||||||
Ans. The assert keyword is used to make an assertion—a statement which the programmer believes is always true at that point in the program. This keyword is intended to aid in testing and debugging. | |||||||||||
Help us improve. Please let us know the company, where you were asked this question : | |||||||||||
Like Discuss Correct / Improve  java   junit.assert   testing   white box testing | |||||||||||
| |||||||||||
Ans. Assert works only if assertions ( -ea ) are enabled which is not required for Verify.Assert throws an exception and hence doesn't continue with the test if assert evaluates to false whereas it's not so with Verify. | |||||||||||
Help us improve. Please let us know the company, where you were asked this question : | |||||||||||
Like Discuss Correct / Improve  assert   junit   mockito   verify   testing   unit testing Asked in 5 Companies | |||||||||||
| |||||||||||
Ans. @Test The Test annotation indicates that the public void method to which it is attached can be run as a test case. @Before The Before annotation indicates that this method must be executed before each test in the class, so as to execute some preconditions necessary for the test. @BeforeClass The BeforeClass annotation indicates that the static method to which is attached must be executed once and before all tests in the class. @After The After annotation indicates that this method gets executed after execution of each test. @AfterClass The AfterClass annotation can be used when a method needs to be executed after executing all the tests in a JUnit Test Case class so as to clean-up the set-up. @Ignores The Ignore annotation can be used when you want temporarily disable the execution of a specific test. | |||||||||||
Help us improve. Please let us know the company, where you were asked this question : | |||||||||||
Like Discuss Correct / Improve  java   junit   jnuit4   junit annotations | |||||||||||
| |||||||||||
Ans. If its a static method of the class , we can use verify to make sure its getting called. If its an instance method , We can mock the object and then use verify with the mocked object to make sure that the method is getting called. | |||||||||||
Help us improve. Please let us know the company, where you were asked this question : | |||||||||||
Like Discuss Correct / Improve  junit   mockito   mock | |||||||||||
| |||||||||||
Ans. In case we need to verify that a method is being called with any argument and not a specific argument we can use Mockito.any(Class), Mockito.anyString, Mockito.anyLong etc. | |||||||||||
Help us improve. Please let us know the company, where you were asked this question : | |||||||||||
Like Discuss Correct / Improve  junit   mockito   mock   mockito.any | |||||||||||
| |||||||||||
Ans. Mockito, PowerMock, EasyMock, JMock, JMockit | |||||||||||
Help us improve. Please let us know the company, where you were asked this question : | |||||||||||
Like Discuss Correct / Improve  junit   mocking frameworks   mock   architecture   white box testing | |||||||||||
| |||||||||||
Ans. @ignore | |||||||||||
Help us improve. Please let us know the company, where you were asked this question : | |||||||||||
Like Discuss Correct / Improve  java   testing   junit   unit testing | |||||||||||
| |||||||||||
Ans. http://javasearch.buggybread.com/CodeSnippets/searchCodeSamples.php?keyword=mock&category=code | |||||||||||
Help us improve. Please let us know the company, where you were asked this question : | |||||||||||
Like Discuss Correct / Improve  Junit  Mock Asked in 1 Companies | |||||||||||
| |||||||||||
Ans. When executing tests it is common that multiple tests need similar objects to be created before they can run. @before specifies a method that provide that initialization for the set of Unit Tests. | |||||||||||
Help us improve. Please let us know the company, where you were asked this question : | |||||||||||
Like Discuss Correct / Improve   | |||||||||||
| |||||||||||
Ans. Yes, that can be done using Power Mock. Mockito doesnt provide a way to mock static methods. | |||||||||||
Help us improve. Please let us know the company, where you were asked this question : | |||||||||||
Like Discuss Correct / Improve  Mockito  junit  powermock Asked in 1 Companies | |||||||||||
| |||||||||||
Ans. Yes, If we are testing a code segment to check if throws / doesn't throw an exception. Moreover while testing void methods, we may just verify and not use assert. | |||||||||||
Help us improve. Please let us know the company, where you were asked this question : | |||||||||||
Like Discuss Correct / Improve  junit  assert | |||||||||||
| |||||||||||
Ans. assertThat is introduced with Junit4 and offers many advatanges over assert. Messages are more explanatory, offer better type safety and are more readable. Moreover hamcrest library is portable as it can used both with junit and TestNG.Moreover assertThat provides flexibility as the same method can be used for assert , assertEquals,assertTrue etc through the use of matcher methods. | |||||||||||
Help us improve. Please let us know the company, where you were asked this question : | |||||||||||
Like Discuss Correct / Improve  assertThat  assert  assert vs assertThat | |||||||||||
| |||||||||||
Ans. is not equals anyOf hasSize | |||||||||||
Help us improve. Please let us know the company, where you were asked this question : | |||||||||||
Like Discuss Correct / Improve  assertThat.hamcrest | |||||||||||
| |||||||||||
This question was recently asked at 'Cognizant ( CTS )'.This question is still unanswered. Can you please provide an answer. | |||||||||||
Help us improve. Please let us know the company, where you were asked this question : | |||||||||||
Like Discuss Correct / Improve   Asked in 1 Companies | |||||||||||
| |||||||||||
Ans. When we Mock an object and then make a reference to any method using mocked object reference , java never makes a call to that method and looks for mocked value to be returned or null if none specified. But If we want that to be overridden and want java to make actual method call upon using mocked object reference, this method can be used. | |||||||||||
Help us improve. Please let us know the company, where you were asked this question : | |||||||||||
Like Discuss Correct / Improve  junit  mocking  java unit testing  Mockito | |||||||||||
| |||||||||||
This question was recently asked at 'Conde Nast'.This question is still unanswered. Can you please provide an answer. | |||||||||||
Help us improve. Please let us know the company, where you were asked this question : | |||||||||||
Like Discuss Correct / Improve  testing  junit Asked in 1 Companies | |||||||||||
| |||||||||||
Ans. By using assertNotNull(employee_address) | |||||||||||
Help us improve. Please let us know the company, where you were asked this question : | |||||||||||
Like Discuss Correct / Improve   Asked in 1 Companies | |||||||||||
| |||||||||||
This question is still unanswered. Can you please provide an answer. | |||||||||||
Help us improve. Please let us know the company, where you were asked this question : | |||||||||||
Like Discuss Correct / Improve   | |||||||||||
| |||||||||||
This question is still unanswered. Can you please provide an answer. | |||||||||||
Help us improve. Please let us know the company, where you were asked this question : | |||||||||||
Like Discuss Correct / Improve   | |||||||||||
| |||||||||||
Ans. Yes, We can pass the test even if the tested method throws an exception. One way is know as exception testing in which the tested method is expected to throw exception and hence the expectation is set accordingly. @Test(expected = IndexOutOfBoundsException.class) public void test(){} Other way is to just ignore if the tested code throws an exception. In that case , we can enclose the tested method call in the try block and within exception block, we just return gracefully. Exception testing is perfectly ok to be done as we would like test code in case an exception occurs and if the code is handling the exception properly. Ignoring the exception by putting the tested method call within try block isn't something normal and should be avoided. | |||||||||||
Help us improve. Please let us know the company, where you were asked this question : | |||||||||||
Like Discuss Correct / Improve  Junit exception testing | |||||||||||
| |||||||||||
Ans. public List convertAllToUpperCase(List words) { return words.stream().map(String::toUpperCase).collect(Collectors.toList()); } @Test public void testAllToUpperCase() { List expected = Arrays.asList("JAVA8", "STREAMS"); List result = convertAllToUpperCase(Arrays.asList("java8", "streams")); assertEquals(expected, result); } | |||||||||||
Help us improve. Please let us know the company, where you were asked this question : | |||||||||||
Like Discuss Correct / Improve  java8  java 8 Asked in 1 Companies | |||||||||||
| |||||||||||
This question is still unanswered. Can you please provide an answer. | |||||||||||
Help us improve. Please let us know the company, where you were asked this question : | |||||||||||
Like Discuss Correct / Improve  Junit   Jasmine   Karma | |||||||||||
| |||||||||||