Q.Explain who should use JUnit – a developer or tester? Why you use
JUnit to test your code?
Ans- JUnit
is more often used by developers to implement unit tests in JAVA. It is
designed for unit testing that is more a coding process and not a testing
process. However, many testers and QA engineers use JUnit for unit testing.
JUnit is used because
It test early and does automate testing.
JUnit
tests can be compiled with the build so that at unit level, regression testing
can be done. It allows test code re-usage.
JUnit tests behave as a document for the unit tests when there is a
transfer.
Q.Describe the
process which is helpful in the creation of parameterized Tests
Ans- In
order to answer this question, you need to take into account that there are
five steps. These steps are as follows:
1. The
first step is that you have to create a public constructor which would take
into account the equivalent value of a row of test related data
2. In the second
step, you have to annotate the test class with a command by the name of @Run
With
3. In
the third step, you have to create a public static procedure which has the
ability to return a collection of test data
sets
4. In the fourth
step, you need to create a viable which is instantaneous and is the source of
data
5. In
the last level, you have to make sure that test case is invoked only once per
each row. This would facilitate the
smooth running of an application.
Q.What is a test
fixture with respect to JUnit?
Ans- A
test fixture is also known as a regulated state of objects that can be used as
a platform for running the tests. The primary purpose is to make sure that
there is a known climate in which the development tests can be run. Various
examples can be cited in this context. They are as follows:
1. Copying the fixed
known set of files
2. Preparing the
input data and the creation of mock and fake objects
3. Assessing a
database with fixed and known sets of data
It
is also essential for you to note that if a group of tests shares the same
fittings, one needs to write a different setup code. On the other hand, if the
group of assessments is in need of a different test fixture, one can write the
code alongside the test procedure. In this manner, one can create the best
accessory related to a test.
Q.What is
mocking and stubbing? Did you use any mocking framework?
Ans- Mocking
is a feature where an object mimics like a real object. Stubbing are codes that
are responsible for taking place of another component.
There are various different Java mocking framework such as Mockito,
EasyMock etc.
Q. What is unit
testing method-naming convention that you follow?
Ans- The convention you follow should have every information required by
the method name in a structured manner. Unit tests name should act like the
documentation giving a clear idea of what functionality is tested. There are
various techniques that could be used to name unit tests. Some of them are the
following: Given… When… Then… Should… etc.
Q. What do
following JUnit test annotations mean?
Ans- Use
of annotations reduces coding and extra burden from the tester. Following is a
list of frequently used JUnit 4 annotations:
@Test (@Test identifies a test method)
@Before (Ans: @Before method will execute before every JUnit4
test)@After (Ans: @After method will execute after every JUnit4
test)@BeforeClass (Ans: @BeforeClass method will be executed before the JUnit
test for a Class starts)@AfterClass (@AfterClass method will be executed
after the JUnit test for a Class is completed)@Ignore (@Ignore method will not
be executed
Q.What are the
important JUnit annotations?
Ans- The test runner
is used to execute the test cases.
@Test: This is
the test method to run first unless otherwise specified.
@BeforeClass:
This is run once before any of the other test methods present in the class.
@Before: This is run before @Test.
@After: As the name suggests, this is run after the @Test.
@AfterClass:
This is run one after all of the tests in the class have been run.
Q.What
are the useful JUnit extensions?
Ans-There are several JUnit extensions such as:
JWebUnit XMLUnit Cactus MockObject
Q.Explain
how you can write a simple JUnit test case?
Ans- The simplest way to write a JUnit
test case is:
Determine a subclass of TestCase
To initialize object(s)
under test, override the setup() method To release
object(s) under test override the teardown()
method
Determine one or more public test XYZ() methods that exercise the
objects under test and assert expected results.
Q.Explain what
is meant by ignoring test in JUnit?
Ans- When
your code is not ready, and it would fail if executed then you can use @Ignore
annotation. It will not execute a test method annotated with @Ignore
It will not execute any of the test methods of test class if it is
annotated with @Ignore
Q.How is code
cyclomatic complexity related to unit tests?
Ans- As
code cyclomatic complexity is determined based on number of decision points
within the code and hence execution paths, higher cyclomatic complexity makes
it difficult to attain achieve test/code coverage
Q.When are the
unit tests pertaining to JUnit written in Developmental Cycle?
Ans- The unit tests are written before the development of the
application. It is so because by writing the check before coding, it assists
the coders to write error-free codes which further boosts the viability of the
form.
3 Comments
real time questions
ReplyDeleteNice Post
ReplyDeleteThat was really a great Article.Thanks for sharing information. Continue doing this.
ReplyDelete