Unit testing

Lakukan tugas rumah & ujian kamu dengan baik sekarang menggunakan Quizwiz!

What are called as test smells in relation with unit testing?

Following could be termed as test smells: Multiple assertions within one unit test, long-running unit tests etc

What do following junit test annotations mean?

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 JUnit test for a Class starts) @AfterClass (Ans: @AfterClass method will be executed after JUnit test for a Class is completed) @Ignore (@Ignore method will not be executed)"

Write a sample unit testing method for testing timeout?

@Test(timeout=100) public void infinity() { while(true); }

What is code coverage? How is it measured? Name some JUnit code coverage tools?

Cobertura, EclEmma

Write a sample unit testing method for testing exception named as IndexOutOfBoundsException when working with ArrayList?

@Test(expected=IndexOutOfBoundsException.class) public void outOfBounds() { new ArrayList<Object>().get(1); }

How is code cyclomatic complexity related to unit tests?

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.

Name some code smells which makes it hard to achieve high code coverage?

Long method, Large conditionals

What are top 2-3 characteristics of Hard-to-test code?

Long methods, Long conditionals, mixing concerns, bulky constructors

With Junit 4, do we still need methods such as setUp and tearDown?

No. This is taken care with help of @Before and @After annotations respectively "

What is mocking & stubbing? What are key differences between them? Did you use any mocking framework?

Read details on What is difference between stubbing and mocking on this page.. There are various different Java mocking framework such as Mockito, EasyMock etc.

What is unit testing?Which unit testing framework did you use? What are some of the common Java unit testing frameworks?

Simply speaking, unit testing is about testing a block of code in isolation. There are two popular unit testing framework in Java named as Junit, TestNG.

What are top 2-3 advantages of mocking?

Verify interactions 2. Test the block of code in isolation

How do one do exception handling unit tests using @Test annotation?

@Test(expected={exception class}. For example: @Test(expected=IllegalArgumentException.class) "

What are top 2-3 advantages of writing unit tests?

Design testability, Code testability, Code maintainability as good unit tests enforces OO principles such as Single Responsitbility etc which enables people avoid code smells such as long classes, long methods, large conditionals etc.

In SDLC, When is the right time to start writing unit tests?

Test-along if not test-driven; Writing unit tests towards end is not very effective. Test-along technique recommends developers to write the unit tests as they go with their development.

What is test-driven development (TDD)?

Test-driven development (TDD) is a software development process that relies on the repetition of a very short development cycle: requirements are turned into very specific test cases, then the software is improved to pass the new tests, only. This is opposed to software development that allows software to be added that is not proven to meet requirements.

What is unit testing method naming convention that you follow?

Unit tests name should act like the documentation giving a clear idea on what functionality is tested. There are various techniques that could be used to name unit tests. Some of them are following: Given...When...Then.. or Should...Then... etc.


Set pelajaran terkait

BOC Prep and NATA-BOC Exam Secrets Study Guide

View Set

pharmacology 1003: Unit 3- respiratory practice questions

View Set

Medical-Surgical Assignment Exam Dr. P

View Set

BCOR350 Chapter 17 Digital Marketing

View Set