Unit Testing In Java

Approved & Edited by ProProfs Editorial Team
The editorial team at ProProfs Quizzes consists of a select group of subject experts, trivia writers, and quiz masters who have authored over 10,000 quizzes taken by more than 100 million users. This team includes our in-house seasoned quiz moderators and subject matter experts. Our editorial experts, spread across the world, are rigorously trained using our comprehensive guidelines to ensure that you receive the highest quality quizzes.
Learn about Our Editorial Process
| By Dthakker11
D
Dthakker11
Community Contributor
Quizzes Created: 3 | Total Attempts: 1,685
Questions: 7 | Attempts: 730

SettingsSettingsSettings
Unit Testing In Java - Quiz

.


Questions and Answers
  • 1. 

    What is test-driven development (TDD)?

    • A.

      Software testers do the development in TDD

    • B.

      The code/implemented and then tests are written.

    • C.

      The Tests are normally written before the Code

    • D.

      TDD does not require unit tests to be written

    Correct Answer
    C. The Tests are normally written before the Code
    Explanation
    Test-driven development (TDD) is a software development approach where tests are written before the actual code implementation. This means that developers first create automated tests that define the desired behavior of the code. These tests are then used as a guide to write the code that will pass the tests. By writing tests first, TDD promotes a more systematic and disciplined approach to development, ensuring that code is designed to meet specific requirements and reducing the risk of introducing bugs or errors.

    Rate this question:

  • 2. 

    Which class your Unit Test should extend to make it a JUnit Test?

    • A.

      JUnitTest

    • B.

      UnitTest

    • C.

      JUnitCase

    • D.

      TestCase

    Correct Answer
    D. TestCase
    Explanation
    To make a Unit Test a JUnit Test, it should extend the "TestCase" class. The "TestCase" class is a base class provided by JUnit framework that provides various methods and assertions to facilitate the testing process. By extending this class, the Unit Test inherits these functionalities and can be executed as a JUnit Test.

    Rate this question:

  • 3. 

    What annotations from the following do you use within your JUnit Test class?

    • A.

      @Before, @After, @Test

    • B.

      @BeforeTest, @AfterTest

    • C.

      @TestTest, @TestThis

    • D.

      @TestClass, @TestMethod

    Correct Answer
    A. @Before, @After, @Test
    Explanation
    The annotations @Before, @After, and @Test are used within a JUnit Test class. @Before is used to specify a method that should be executed before each test method in the class. @After is used to specify a method that should be executed after each test method. @Test is used to specify a method as a test method that will be executed by the JUnit framework. These annotations help in setting up the necessary preconditions before each test, performing the test, and cleaning up any resources after the test is executed.

    Rate this question:

  • 4. 

    @Before gets executed before each test. True/False?

    • A.

      True

    • B.

      False

    Correct Answer
    A. True
    Explanation
    The "@Before" annotation in testing frameworks is used to define a method that needs to be executed before each test case. This method is typically used to set up any necessary preconditions or initialize variables before running the test. Therefore, the statement "True" is correct as the "@Before" method does indeed get executed before each test.

    Rate this question:

  • 5. 

    Who is expected to write Unit Tests?

    • A.

      Software Tester

    • B.

      Designer

    • C.

      Developer

    • D.

      Client

    Correct Answer
    C. Developer
    Explanation
    Developers are expected to write unit tests. Unit tests are a type of software testing where individual components or units of a software system are tested to ensure that they are functioning correctly. Since developers are responsible for writing the code for these components, they are also expected to write the corresponding unit tests to verify their functionality. This helps in identifying and fixing any issues or bugs early in the development process, ensuring the overall quality of the software.

    Rate this question:

  • 6. 

    When should you write Unit Tests?

    • A.

      When you start coding

    • B.

      In Parallel with your coding

    • C.

      Only when needed

    • D.

      At the end when your application is ready

    Correct Answer(s)
    A. When you start coding
    B. In Parallel with your coding
    Explanation
    Unit tests should be written when you start coding and in parallel with your coding. Writing unit tests from the beginning helps in identifying and fixing bugs early in the development process. It also ensures that the code is working as expected and provides a safety net for making changes or refactoring later on. Writing unit tests in parallel with coding promotes a test-driven development approach, where tests are written before the actual implementation, helping to drive the design and ensuring that the code meets the desired requirements.

    Rate this question:

  • 7. 

    What is the smallest Unit you test/target in your Unit Testing?

    • A.

      Constants and Variables

    • B.

      Class

    • C.

      Method and functions

    • D.

      Package

    Correct Answer
    C. Method and functions
    Explanation
    In unit testing, the smallest unit that is tested or targeted is a method or function. Unit testing involves testing individual units of code in isolation to ensure that they function correctly. Methods and functions are the building blocks of code and testing them individually helps in identifying and fixing any bugs or issues at a granular level. Testing constants and variables may not provide comprehensive coverage as they do not involve the execution of code logic. Similarly, testing at the class or package level would be more of integration or system testing rather than unit testing.

    Rate this question:

Quiz Review Timeline +

Our quizzes are rigorously reviewed, monitored and continuously updated by our expert board to maintain accuracy, relevance, and timeliness.

  • Current Version
  • Mar 21, 2023
    Quiz Edited by
    ProProfs Editorial Team
  • Feb 19, 2018
    Quiz Created by
    Dthakker11
Back to Top Back to top
Advertisement
×

Wait!
Here's an interesting quiz for you.

We have other quizzes matching your interest.