Java Unit Testing

Pataasin ang iyong marka sa homework at exams ngayon gamit ang Quizwiz!

assertNull(foo);

Assume we have a null variable foo. Which is the correct way to use assert statements when writing JUnit tests with student.TestCase? A. assertEquals(null, foo); B. assertTrue(foo == null); C. assertNull(foo); D. All of the above

Each time before a test method is executed.

For any JUnit test class, when is the "setUp()" method executed?

3

If there is an if statement with 2 conditions, how many tests cases are necessary?

D. 14, 15, 49, 50 The boundary values are those at the boundary and those respectively one before and one past the boundary,

Imagine a class named Club, to be a member a person must be aged 15 or older, but less than 50. What values would you use to boundary test a method designed to check if a person was a suitable age to join? A. 14, 15, 50, 51 B. 15, 16, 50, 51 C. 15, 16, 49, 50 D. 14, 15, 49, 50 E. 14, 15, 49, 52

You have written separate test cases for each identifiable "group" of input values and/or output values where the behavior is expected to be similar.

Suppose you are writing a method in a new class. You are also writing unit test cases to demonstrate that this method works correctly. You know you have written enough test cases to demonstrate the method works as desired when?

assertTrue or assertFalse

When testing a method that returns a boolean, what assert statements should you use?

public void setUp() {}

Which method is run before each test method?

assertNull(50-25-25);

Which of the following JUnit tests will fail? A. assertNull(50-25-25); B. assertFalse(!(true==!false)); C. assertEquals(-(-10-6),16); D. assertTrue(!false);

D. Test each piece of your solution as you build it, so you will find errors as quickly as possible. Incrementally testing your code as you write it helps you find errors more quickly, and ensures that new work builds on previous work you have already confirmed works. The other four choices here represent less effective or impractical advice.

Which of the following recommendations for testing software is good advice? A. Limit your test cases to one assertion, since each test should check only one expected outcome. B. Save your testing until after the solution is completely written, so you can concentrate solely on testing without distractions. C. Test a program with all possible values of input data. D. Test each piece of your solution as you build it, so you will find errors as quickly as possible. E. Longer tests that focus on combinations of multiple features are preferable, because they test your code more strenuously.


Kaugnay na mga set ng pag-aaral

CH 41 Sexually Transmitted Infections

View Set

Chapter 29: The Fetal Genitourinary System

View Set

Combo with "HaDoop" and 27 others

View Set

Chapter 5- Market for Foreign Exchange

View Set

22 Herzberg's Motivation-Hygiene Theory

View Set

Simple and Multiple Linear Regression

View Set