Since we built the environment to copy the book "[Test Driven Development by Kent Beck, translated by Takuto Wada]" (https://www.amazon.co.jp/dp/B077D2L69C/), the procedure Leave.
--Use Eclipse. ――I want to proceed in the same environment as books. ――I want to see how JUnit works with Eclipse. --No detailed settings. ――If you can't use it for the time being, it won't start. It will be gradually usable later.
Download and install the Eclipse IDE for Java Developers from here. Then press the icon to start it.
When you start it, the following will appear, but you can do nothing here and use [Launch].
This will bring up the first screen.
Select [Create a new Java project] on the screen after startup.
Enter the project name (tdds
) and click Finish.
The project is done.
Add the JUnit library.
Right-click on the project (tdds
) and select Properties.
Select [Java Build Path] and press [Libraries], [Add Library ..].
Select JUnit and press [Next].
Press [Finish].
You have now added JUnit.
MoneyTest
and Dollar
classesThis will start copying sutras. Immediately, try adding the MoneyTest
class and the Dollar
class described in books P4 to P6.
First, add the MoneyTest
class.
Right-click on src
and press [New], [Class].
Enter the Name as MoneyTest
and press [Finish].
I was able to add it.
At this rate, the package name has become tdds
. Modify the package name to money
as in the book.
Right click on the package name. Press [Refactor], [Rename].
Enter the New name as money
and press OK.
The package name change is complete.
Next, create Dollar.java
in the same way.
In the created MoneyTest.java
and Dollar.java
, implement the following as shown in books P4 to P6.
MoneyTest.java
package money;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.*;
public class MoneyTest {
@Test
public void testMultiplication() {
Dollar five = new Dollar(5);
five.times(2);
assertEquals(10, five.amount);
}
}
Dollar.java
package money;
class Dollar {
int amount;
Dollar(int amount) {
}
void times(int multiplier) {
}
}
You can run the test by right-clicking on the project and pressing [Run As]-[1 JUnit Test].
In this way, the test result of JUnit comes out.
If you press here,
The test results will appear in the Console.
This says ʻexpected: <10> but was: <0>`, that is, "10 was expected as an output, but it was 0".
Now you can run the first code in the book. After that, you can copy the sutras in this condition.
Java didn't need to be installed, probably because it was already set during Android application development. It may be necessary to set it again in other environments.
-Building an environment for "test-driven development" copying sutras starting from the terminal -Install Eclipse on Mac and Japaneseize it
Recommended Posts