Unit Testing Fundamentals MCQs

  1. Which annotation in JUnit marks a test method?
    a) @Test
    b) @Run
    c) @Execute
    d) @Case
    View Answer

    Correct answer: A — @Test

  2. In PyTest, test functions must start with:
    a) run_
    b) test_
    c) check_
    d) case_
    View Answer

    Correct answer: B — test_

  3. NUnit in C# uses which attribute for test methods?
    a) [Run]
    b) [Execute]
    c) [Test]
    d) [Case]
    View Answer

    Correct answer: C — [Test]

  4. Which of the following is NOT a unit testing framework?
    a) JUnit
    b) PyTest
    c) NUnit
    d) Maven
    View Answer

    Correct answer: D — Maven

  5. What is the purpose of assertions in unit testing?
    a) Validate expected results
    b) Run multiple threads
    c) Manage databases
    d) Deploy applications
    View Answer

    Correct answer: A — Validate expected results

  6. Which JUnit annotation runs before each test method?
    a) @Before
    b) @After
    c) @Init
    d) @Setup
    View Answer

    Correct answer: A — @Before

  7. Which JUnit annotation runs after each test method?
    a) @After
    b) @Before
    c) @Cleanup
    d) @End
    View Answer

    Correct answer: A — @After

  8. In PyTest, fixtures are defined using:
    a) @fixture
    b) @pytest.fixture
    c) @setup
    d) @mock
    View Answer

    Correct answer: B — @pytest.fixture

  9. Which NUnit attribute runs once before all tests in a class?
    a) [SetUp]
    b) [TearDown]
    c) [OneTimeSetUp]
    d) [Init]
    View Answer

    Correct answer: C — [OneTimeSetUp]

  10. Which of the following is true about unit tests?
    a) They test individual components
    b) They test entire systems
    c) They replace integration tests
    d) They are not automated
    View Answer

    Correct answer: A — They test individual components

  11. What will be printed?
    1 import org.junit.Test;
    2 public class EduinqTest {
    3 @Test
    4 public void sample() {
    5 System.out.println("Eduinq Unit Test");
    6 }
    7 }
    a) Eduinq Unit Test
    b) sample
    c) No output
    d) Compilation error
    View Answer

    Correct answer: A — Eduinq Unit Test

  12. Which PyTest command runs all tests in a directory?
    a) pytest .
    b) runpytest
    c) testpy
    d) python -m test
    View Answer

    Correct answer: A — pytest .

  13. NUnit tests are executed using:
    a) nunit-console
    b) runnunit
    c) dotnet run
    d) testnunit
    View Answer

    Correct answer: A — nunit-console

  14. Which JUnit assertion checks equality?
    a) assertEquals
    b) assertTrue
    c) assertNull
    d) assertNotSame
    View Answer

    Correct answer: A — assertEquals

  15. PyTest uses which keyword to mark expected exceptions?
    a) pytest.raises
    b) pytest.exception
    c) pytest.error
    d) pytest.fail
    View Answer

    Correct answer: A — pytest.raises

  16. NUnit's [TearDown] attribute is used for:
    a) Cleanup after each test
    b) Setup before each test
    c) Running all tests
    d) Skipping tests
    View Answer

    Correct answer: A — Cleanup after each test

  17. Which of the following is NOT an assertion in JUnit?
    a) assertEquals
    b) assertTrue
    c) assertFalse
    d) assertRun
    View Answer

    Correct answer: D — assertRun

  18. PyTest supports parameterized tests using:
    a) @pytest.mark.parametrize
    b) @pytest.parameter
    c) @pytest.args
    d) @pytest.values
    View Answer

    Correct answer: A — @pytest.mark.parametrize

  19. NUnit supports ignoring tests using:
    a) [Ignore]
    b) [Skip]
    c) [Disable]
    d) [Stop]
    View Answer

    Correct answer: A — [Ignore]

  20. Which of the following is true about unit testing frameworks?
    a) They provide automation support
    b) They cannot run in IDEs
    c) They only support manual testing
    d) They replace CI/CD tools
    View Answer

    Correct answer: A — They provide automation support

  21. What will be printed?
    1 def test_sample():
    2 print("Eduinq PyTest")
    a) Eduinq PyTest
    b) test_sample
    c) No output
    d) Error
    View Answer

    Correct answer: A — Eduinq PyTest

  22. JUnit tests can be grouped using:
    a) Test suites
    b) Test clusters
    c) Test packages
    d) Test groups
    View Answer

    Correct answer: A — Test suites

  23. PyTest fixtures are useful for:
    a) Reusable setup/teardown
    b) Logging
    c) Monitoring
    d) Deployment
    View Answer

    Correct answer: A — Reusable setup/teardown

  24. NUnit supports parameterized tests using:
    a) [TestCase]
    b) [Param]
    c) [Args]
    d) [Values]
    View Answer

    Correct answer: A — [TestCase]

  25. Which JUnit annotation disables a test?
    a) @Ignore
    b) @Disable
    c) @Skip
    d) @Stop
    View Answer

    Correct answer: A — @Ignore

  26. PyTest command to run a specific test file:
    a) pytest filename.py
    b) runpytest filename.py
    c) python filename.py
    d) test filename.py
    View Answer

    Correct answer: A — pytest filename.py

  27. NUnit supports assertions like:
    a) Assert.AreEqual
    b) Assert.EqualTo
    c) Assert.Same
    d) Assert.Run
    View Answer

    Correct answer: A — Assert.AreEqual

  28. JUnit 5 introduced which annotation for test methods?
    a) @Test
    b) @RunTest
    c) @Execute
    d) @Case
    View Answer

    Correct answer: A — @Test

  29. PyTest supports skipping tests using:
    a) @pytest.mark.skip
    b) @pytest.skip
    c) @pytest.ignore
    d) @pytest.stop
    View Answer

    Correct answer: A — @pytest.mark.skip

  30. NUnit supports expected exceptions using:
    a) Assert.Throws
    b) Assert.Exception
    c) Assert.Error
    d) Assert.Fail
    View Answer

    Correct answer: A — Assert.Throws

  31. Which of the following is true about JUnit assertions?
    a) They validate test results
    b) They deploy applications
    c) They monitor logs
    d) They manage databases
    View Answer

    Correct answer: A — They validate test results

  32. PyTest supports fixtures with scope defined as:
    a) function, class, module, session
    b) test, suite, package, run
    c) local, global, static, dynamic
    d) init, setup, teardown, cleanup
    View Answer

    Correct answer: A — function, class, module, session

  33. NUnit supports setup methods using:
    a) [SetUp]
    b) [Init]
    c) [Before]
    d) [Start]
    View Answer

    Correct answer: A — [SetUp]

  34. JUnit supports running tests with:
    a) IDEs and build tools
    b) Only IDEs
    c) Only command line
    d) Only Maven
    View Answer

    Correct answer: A — IDEs and build tools

  35. PyTest supports marking tests using:
    a) @pytest.mark
    b) @pytest.tag
    c) @pytest.case
    d) @pytest.run
    View Answer

    Correct answer: A — @pytest.mark

  36. NUnit supports categories using:
    a) [Category]
    b) [Group]
    c) [Tag]
    d) [Suite]
    View Answer

    Correct answer: A — [Category]

  37. Which JUnit annotation runs once before all tests?
    a) @BeforeClass
    b) @Before
    c) @Init
    d) @Setup
    View Answer

    Correct answer: A — @BeforeClass

  38. PyTest supports custom markers defined in:
    a) pytest.ini
    b) pytest.json
    c) pytest.yaml
    d) pytest.config
    View Answer

    Correct answer: A — pytest.ini

  39. NUnit supports teardown methods using:
    a) [TearDown]
    b) [Cleanup]
    c) [After]
    d) [End]
    View Answer

    Correct answer: A — [TearDown]

  40. JUnit supports assertions like:
    a) assertTrue, assertFalse
    b) assertRun, assertStop
    c) assertDeploy, assertMonitor
    d) assertDB
    View Answer

    Correct answer: A — assertTrue, assertFalse

  41. PyTest supports running tests in parallel using:
    a) pytest-xdist
    b) pytest-parallel
    c) pytest-runner
    d) pytest-multi
    View Answer

    Correct answer: A — pytest-xdist

  42. NUnit supports ignoring tests with reason using:
    a) [Ignore("reason")]
    b) [Skip("reason")]
    c) [Disable("reason")]
    d) [Stop("reason")]
    View Answer

    Correct answer: A — [Ignore("reason")]

  43. JUnit supports exception testing using:
    a) assertThrows
    b) assertException
    c) assertError
    d) assertFail
    View Answer

    Correct answer: A — assertThrows

  44. PyTest supports marking tests to run conditionally using:
    a) @pytest.mark.skipif
    b) @pytest.mark.condition
    c) @pytest.mark.ifskip
    d) @pytest.mark.runif
    View Answer

    Correct answer: A — @pytest.mark.skipif

  45. In JUnit, which assertion checks if an object is null?
    a) assertNull
    b) assertEmpty
    c) assertNone
    d) assertZero
    View Answer

    Correct answer: A — assertNull

  46. NUnit supports running tests in parallel using:
    a) [Parallelizable]
    b) [Concurrent]
    c) [MultiThread]
    d) [Async]
    View Answer

    Correct answer: A — [Parallelizable]

  47. Which JUnit annotation runs once after all tests?
    a) @AfterClass
    b) @After
    c) @Cleanup
    d) @End
    View Answer

    Correct answer: A — @AfterClass

  48. PyTest supports marking tests as expected to fail using:
    a) @pytest.mark.xfail
    b) @pytest.mark.fail
    c) @pytest.mark.error
    d) @pytest.mark.skip
    View Answer

    Correct answer: A — @pytest.mark.xfail

  49. NUnit supports test case sources using:
    a) [TestCaseSource]
    b) [CaseSource]
    c) [SourceTest]
    d) [DataCase]
    View Answer

    Correct answer: A — [TestCaseSource]

  50. Which of the following best describes unit testing?
    a) Testing individual components in isolation
    b) Testing the entire system end-to-end
    c) Testing only performance aspects
    d) Testing only security vulnerabilities
    View Answer

    Correct answer: A — Testing individual components in isolation

Quick Links to Explore