Week 8: Software Testing (Part 2) - CS 427

Réussis tes devoirs et examens dès maintenant avec Quizwiz!

F

(T/F): A big test is better than several small tests.

T

(T/F): A reason that a big test is worse than several small tests is that the later assertions won't be executed if the preceding one assertion fails.

T

(T/F): A test method annotated with @Ignore will not be executed.

F (you would need to annotate the method with @BeforeEach)

(T/F): Annotating a public void method with @AfterEach causes that method to be run before each test method (i.e., a method annotated with @Test).

T

(T/F): Explicit conversion should be used with @ConvertWith

T

(T/F): If equal method doesn't get overwritten, assertSame and assertEqual work in the same way.

T

(T/F): If the boolean statement in the assumeTrue method is false, then we skip the rest of the test code (similarly with assumeFalse).

T

(T/F): If we want only specific values from the Enum, we can do that using @EnumSource name parameter.

F (only both together are)

(T/F): Just high code coverage or large number of assertions is a good quality indicator.

T

(T/F): One can use an automatic test generation tool to construct a small test suite with high coverage

F (update reasoning after getting response from CampusWire)

(T/F): See the photo attached. The above two unit tests have exactly the same effect at runtime.

T

(T/F): Testing can be used in the process of checking the functionalities of a software application to see whether it is working correctly as per its functional requirements.

T

(T/F): To support the @CsvSource, Junit provides conversions to convert String to target types.

T (they exercise little code and failures are easy to debug)

(T/F): Unit tests have a short feedback loop.

T

(T/F): We can pass CSV values to test methods. We can specify the delimiter for multiple arguments in the test method.

T (see photo attached in the question for an example of custom aggregation)

(T/F): We can use @AggregateWith to custom aggregator.

T

(T/F): We can use @MethodSource to specify a factory method for test arguments. The factory method should be static.

T

(T/F): We can use @MethodSource to specify a parameterized factory method. Then the return type of this factory method can be Stream, Iterator, Iterable, or array of element sets.

T

(T/F): We use @DisplayName to specify a custom name that is easy to read and provide information about the test class and method.

T (for assumeThat statements, we don't skip the rest of the test method if the boolean argument is false, we only skip the executable code in the second parameter)

(T/F): We will still continue the remaining of the test code even if the assumption, the first boolean argument of assumeThat is false.

F (if one of the assertions in the assertAll statement fails, it will still continue to check the assertions after the one that failed; it will always check all assertions in the method)

(T/F): assertAll won't continue to check if one of the assertions is not passed.

T

(T/F): assertSame asserts that expected and actual refer to the same object.

T

(T/F): assertThrows asserts that execution of the supplied execrable throws an exception of the expectedType and returns the exception.

assumption first (property second)

A guideline for writing properties such that we first all-combine possible returns of observers, then formulate properties specific under each feasible combination as assumption (then follow the property-first guideline under such assumption).

property first (assumption second)

A guideline for writing properties where we first classify methods to be either modifiers or observers, then pairwise-combine them (each observer paired with a modifier, each modifier paired with another modifier including itself) to formulate properties, then add proper assumptions to make the properties (ex: equality, inequality) true.

C

A parameterized test class must carry which annotation? A) @Test B) @ParameterisedClass C) @ParameterizedTest D) @Class

explicit conversion (there is a method explicitly written out to convert a single string into an array of strings where each element will be split by commas between numbers, and there is a @ConvertWith annotation to specify the class to use for this conversion)

See the photo attached. What type of conversion does this program use? (implicit/explicit)

C (assertSame fails because the two arguments are not the same object and assertEquals passes because the two arguments are equal to each other as the equals method would return true in this case)

See the photo attached. What will be the results of the above two assertions after the two test methods are run? A) Pass, Pass B) Pass, Fail C) Fail, Pass D) Fail, Fail

N (The line before assumes that the operating system is not windows. But since we are running on a Windows operating system, this assertion is false. Because of this, the program will not be running the rest of the test method after the assertion statement.)

See the photo attached. Will the line annotated with comment of "line*" get executed in a Windows operating system? (Y/N)

Equals, Same

The assert_____(Object expected, Object actual) method asserts that expected and actual are equal, using the equals() method. The assert_____(Object expected, Object actual) method asserts that expected and actual refer to the same object.

implicit conversion

The conversion of data type which is done by the compiler on its own, without any external trigger from the user. In the attached photo, String gets __________ converted to TimeUnit.

explicit conversion

The data type transformation from one type to another caused by using a cast operator, triggered by the user typing it. Should be used with @ConvertWith In the attached photo, TimeUnit gets ________ converted to String. in order to match the type specified by the parameter in the test method. This is done by @ConvertWith specifying the class used to convert the source object into a String. In the assertion statement, the String gets converted back to a TimeUnit.

B

The test class must carry the @RunWith annotation with the ______ class as its argument. A) Default B) Parameterized C) Super D) Inherited

add assumptions (test generalization)

The third step in test generalization. Adds assumptions to prevent illegal values for the parameters or enable the assertions to be valid (ex: ensure that the stack parameter isn't null before running the rest of the test method) See photo attached for visualization.

assumption-first guideline

We specifically listed, formulated, and tested all possible returns of observers. What guideline is it? (assumption-first/property-first)

A

What are Parameterized tests used for in JUnit? A) Run a test many times with different sets of parameters B) Run a test with no parameters C) Run a test with only String parameters D) Run a test once with fixed set of parameters

C

What is test-driven development (TDD)? A) Software testers perform the development. B) The code/implemented first and then tests are written. C) The tests are written before the implementation. D) Write code without unit tests.

assume, arrange, act, assert

What is the General 4A pattern used to write parameterized tests?

assume

Which of the General 4A is representative of line1? (assume/arrange/act/assert)

act

Which of the General 4A is representative of line3? (assume/arrange/act/assert)

C

Which of the following assert function checks that an object isn't null? A) void assert(Object object, boolean toCheckAsNull) B) void assertCheck(Object object, boolean toCheckAsNull) C) void assertNotNull(Object object) D) void assertChecks(Object object, boolean toCheckAsNull)

D

Which of the following is NOT test generalization step? A) Parameterize B) Generalize test oracle C) Add assumptions D) Classify methods

B (the third argument in assertEquals is only needed for comparing double and float types)

Which of the following is a valid JUnit API method signature? A) static void assertEquals(char expected, char actual, double delta) B) static void assertEquals(double expected, double actual, double delta) C) static void assertEquals(long expected, long actual, double delta)

C

Which of the following is correct about JUnit? A) It provides test runners to run tests. B) JUnit tests can be run automatically and they check their own test results and provide immediate feedback of failing or passing C) Both A and B D) None

B (when comparing doubles and floats, you need a third argument for assertEquals that specifies the given delta/range in which expected and actual can differ by but still be classified as equal)

Which of the following is correct? A) static void assertEquals(byte expected, byte actual, double delta) B) static void assertEquals(double expected, double actual, double delta) C) static void assertEquals(double expected, double actual)

D

Which of the following is the purpose of Junit Test? A) To check whether the behaviors for the previous versions are preserved during the software evolution. B) To provide a short feedback loop, because unit tests excise small portions of the code, one at the time C) To provide a useful documentation in order to allow developers or other users of the system to better understand how the system behaviors would be walking out. D) All

D

Which of the following types can be converted by implicit conversion? A) Float B) Short C) Enum subclass D) All

A (this happens in the first step of the property-first guideline)

Which of the followings does NOT belong to Assumption-First Guideline? A) Classify methods B) Pairwise-combine methods to formulate properties C) Formulate properties specific under each feasible combination of observers' return as assumption D) Add proper assumptions to make the properties

C (this happens in the second step of the assumption-first guideline)

Which of the followings does NOT belong to Property-First Guideline? A) Classify methods B) Pairwise-combine methods to formulate properties C) Formulate properties specific under each feasible combination of observers' return as assumption D) Add proper assumptions to make the properties

C

Which step does adding assumptions to prevent illegal values for the parameters refers to? A) Parameterize B) Generalize test oracle C) Add assumptions D) Cross test generalize

D

Which step does generalizing further across multiple tests refers to? A) Parameterize B) Generalize test oracle C) Add assumptions D) Cross test generalize

A (the first part of parameterization is where the elements used as input to the receiver object in the test become arguments instead of variables with magic numbers)

Which step does promoting all primitive values as arguments refers to? A) Parameterize B) Generalize test oracle C) Add assumptions D) Cross test generalize

B

Which step does replacing constant values in assertions with some generalized expressions refers to? A) Parameterize B) Generalize test oracle C) Add assumptions D) Cross test generalize

A (we convert the non-primitive objects such as receiver objects from a test method into parameters for that test)

Which test generalization steps have non-primitive objects as arguments? A) Parameterize B) Generalize test oracle C) Add assumptions D) Cross test generalize

C

Which test-generalization steps use AssumeTrue or AssumeFalse? A) Parameterize B) Generalize test oracle C) Add assumptions D) Cross test generalize

implicit

See the photo attached. What type of conversion does it use? (implicit/explicit)

parameterized test

A feature of JUnit that allows us to execute a single test method multiple times with different parameters.

unit test

A test of each individual component (often a program) with assertions to ensure that it is as defect-free as possible.

assertAll (static void assertAll(String heading, Executable... executables))

Assertion method that asserts that all supplied executables do not throw exceptions. It always checks all of the assertions that are passed to it, no matter how many fail. If all pass, all is fine - if at least one fails you get a detailed result of all that went wrong (and right for that matter).

assertThrows (static T assertThrows(Class expectedType, Executable executable))

Assertion method that asserts that execution of the supplied executable throws an exception of the expectedType and returns the exception.

A (the API method would be assumeThat if it has two arguments)

Assuming that an API method has two arguments, they should be ordered by: A) The first one as Boolean assumption, second one being Executable. B) The first one as Executable, second one being Boolean assumption.

assumeFalse (static void assumeFalse(boolean assumption))

Assumption method that takes in a boolean statement. If the statement is false, then we run the remainder of the code in the test method that the assumption is included in. Otherwise, we skip the rest of the method.

assumeTrue (static void assumeTrue(boolean assumption))

Assumption method that takes in a boolean statement. If the statement is true, then we run the remainder of the code in the test method that the assumption is included in. Otherwise, we skip the rest of the method.

assumeThat (static void assumeThat(boolean assumption, Executable executable))

Assumption method that takes two arguments, the first being a boolean statement and the second being an executable. If the boolean statement is true, then we run the executable code in the second parameter. If the boolean statement is false, then we skip the executable code in the second parameter.

D

How can we determine the quality of the unit tests? A) Code coverage: all parts of the program under test exercised by the unit test. B) Reflect the expected behavior of the code and the test. C) Only need one of the two D) Both

D

How to make sure a test is readable? A) Describing the intentions of the unit test. B) Delete duplicated or redundant tests. C) Only need one of the two D) Both

@ValueSource

If a test method is a parameterized test, then the method should use the tag of ________ to provide arguments for each invocation of the parameterized test, that is, to specify the source of its arguments.

@AfterEach

If we want to run a method after each test method (ex: a method that asserts that the stack is not empty), what should we annotate the method with?

@BeforeEach

If we want to run a method before each test method (ex: creating a stack), what should we annotate the method with?

assertion, assumption, annotation (Assertions are the assert statements we see in tests, assumptions are assumeTrue(boolean assumption), assumeFase(boolean assumption), assumeThat(boolean assumption, Executable executable), annotations are the @ statements)

List the 3 main JUnit features.

N (because the print "1" statement is in the executable code argument of a assumeThat statement with a false condition, it will not get printed)

Observe the code in the photo attached. Will "1" get printed? (Y/N)

Y (because a false condition in the assumeThat method will only skip over the executable code argument; the program will still run everything after the assumeThat statement regardless of if the boolean statement is true or not)

Observe the code in the photo attached. Will "2" get printed? (Y/N)

parameterize (test generalization)

The first step in test generalization. Pushes all primitive values as arguments for the test (such as an integer (s) to be pushed into a stack) then pushes non-primitive objects such as receiver objects as arguments for the test (such as an empty stack that will be taking in integers). See photo attached for visualization.

cross-test generalize (test generalization)

The last step in test generalization. Generalizes further across multiple tests such that you can combine them into one and the functionalities of the multiple tests will all be covered in that new, single test. See photo attached for visualization.

test generalization

The process of generalizing conventional tests to parameterized tests so that we can have a stronger capability and lower redundancies among the unit tests that we are writing for a class and the test such as a stack. Four steps: 1. Parameterize 2. Generalize test oracle 3. Add assumptions 4. Cross-test generalize

argument aggregation

The process of taking arguments from an input argument framework and converting it into a desired (different) output argument framework. In the attached photo, the parametrized test method is first run with the Jane Doe string. It parses out the arguments from the string and converts them to the necessary type (like converting "F" to Gender.F and "1990-05-20" into a LocalDate object). These new arguments are what create a new Person object. After going through the rest of the test method, the process is repeated for the next string in the CsvSource, which is the John Doe string.

generalize test oracle (test generalization)

The second step in test generalization. Replaces constant values in assertions with some generalized expression (ex: magic numbers with variables used in an expression). See photo attached for visualization.


Ensembles d'études connexes

Administration and Communication II

View Set

sport psychology chap 3 motivation

View Set

Texas Real Estate Principles 1 (Allied)

View Set

Biology lesson 3.20 Respiration and photosynthesis

View Set