You are on page 1of 3

Bài

2 – Chủ đề: Junit-Tests (Junit 5 not Junit4!) for Array-Methods


Code Template thầy em cho trước ạ:

Clone the repository URL: (Anh copy URL này vào Intellij/Eclipse ạ.)

https://ge87hes@bitbucket.ase.in.tum.de/scm/PGDP2223W03H02/pgdp2223w03h02-
ge87hes.git

Username của em: ge87hes

Password: Mermaid7618

Introduction:

Array methods that are required for processing large amounts of data and now need to be tested.
Think carefully about which errors could have crept into the implementations and which tests can be
used to discover them.

The code template provided with this task already contains an example test, so all you have to do to
complete this task is add JUnit 5 to your IDE and then write any number of methods over it with the
@Test annotation, in which you test the methods listed below.

Junit5: Setup with Gradle

1. Setup with Gradle


In order to be able to use JUnit with Gradle (our build tool), a block called 'dependencies'
must appear in the 'build.gradle' file and the JUnit version to be used must be specified in this
block (see image). We use JUnit 5.


2. Assertions
We want to compare the expected and the actual output.
JUnit offers a functionality that displays the test results in the IDE: Assertions. A call to the
method assertEquals(expected, actual) runs through if expected.equals(actual), if not, an
AssertionError is thrown and the test failed. This is then displayed in the IDE.


3. Imports
In order to be able to use the functionality of JUnit 5 in a class, you first have to import it. The
imports of the annotations and assertions look something like this:

Make sure that the annotations and assertions are imported from the Jupiter API, i.e. that the
string "jupiter" is included in the import statement.

Đề bài:

In the pgdp.tests package you will find the ArrayTest class, in which you should now implement tests
for the following methods:

• print()
• minAndMax()
• invert()
• intersect()
• inearize()
• bubbleSort()

bubbleSort is a method that sorts a given array in ascending order. So inputting [3, 1, 4, 5, 2] returns
array [1, 2, 3, 4, 5] and inputting [4, 3, 4, 1, 1] returns array [1, 1 , 3, 4, 4] is returned.

We have prepared some flawed implementations of the six methods to be found in our tests of your
tests. Write enough tests for each method to find all of these incorrect implementations. Of course,
we won't show you our flawed implementations of the six methods. After all, testing is about finding
errors in a program without looking at the actual program code. However, with each push we already
tell you for each of the six methods whether you have found all wrong implementations. After each
push, you know immediately how many of the six maximum achievable points you would receive with
this after the deadline.

Attention: To test console output please use PinguLib.getConsoleOutput()

Structure of the repository:

The PinguLib can help you to read output from the console.

• Before each test, the setup() method must be executed,


• then the output on the console can be read with getConsoleOutput(),
• and after each test, the reset() method must be executed.
• In the pgdp.array package you will find the correct implementation of the above methods. For
practical reasons, the implementations are in the ArrayInterface, which are called by the Array
class. The most important thing for you is that you can access the methods via the imports in
ArrayTest. If you want to try faulty implementations, you can change the method bodies in the
ArrayInterface as you like.

Tips:

• No more than 4 tests are required per method


• More than one test is usually required per method
• Here you will find under "Annotation Interfaces" the documentation of some annotations of
JUnit-5, which can be useful
https://junit.org/junit5/docs/current/api/org.junit.jupiter.api/org/junit/jupiter/api/package-
summary.html

You might also like