[JAVA] Building an environment for copying the book "Test Driven Development"

Introduction

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.

Construction policy

--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.

environment

procedure

Install and launch

Download and install the Eclipse IDE for Java Developers from here. Then press the icon to start it.

スクリーンショット 2017-12-17 18.32.52.png

When you start it, the following will appear, but you can do nothing here and use [Launch].

スクリーンショット 2017-12-17 18.22.19.png

This will bring up the first screen.

Creating a project

Select [Create a new Java project] on the screen after startup.

スクリーンショット 2017-12-17 18.15.17.png

Enter the project name (tdds) and click Finish.

スクリーンショット 2017-12-17 18.15.38.png

The project is done.

スクリーンショット 2017-12-17 18.22.37.png

Add JUnit

Add the JUnit library. Right-click on the project (tdds) and select Properties.

スクリーンショット 2017-12-17 18.46.56.png

Select [Java Build Path] and press [Libraries], [Add Library ..].

スクリーンショット 2017-12-17 18.16.35.png

Select JUnit and press [Next].

スクリーンショット 2017-12-17 18.16.38.png

Press [Finish].

スクリーンショット 2017-12-17 18.16.41.png

You have now added JUnit.

Added MoneyTest and Dollar classes

This 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].

スクリーンショット 2017-12-17 19.00.08.png

Enter the Name as MoneyTest and press [Finish].

スクリーンショット 2017-12-17 18.24.19.png

I was able to add it.

スクリーンショット 2017-12-17 18.24.26.png

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].

スクリーンショット 2017-12-17 18.24.55.png

Enter the New name as money and press OK.

スクリーンショット 2017-12-17 18.25.11.png

The package name change is complete. Next, create Dollar.java in the same way.

スクリーンショット 2017-12-17 18.25.25.png

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) {

    }
}

Run the test

You can run the test by right-clicking on the project and pressing [Run As]-[1 JUnit Test].

スクリーンショット 2017-12-17 18.26.28.png

In this way, the test result of JUnit comes out.

スクリーンショット 2017-12-17 18.26.38.png

If you press here,

スクリーンショット 2017-12-17 18.26.38のコピー.png

The test results will appear in the Console.

スクリーンショット 2017-12-17 18.26.48.png

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.

Remarks

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.

Referenced page

-Building an environment for "test-driven development" copying sutras starting from the terminal -Install Eclipse on Mac and Japaneseize it

Recommended Posts

Building an environment for copying the book "Test Driven Development"
Building an environment for "test-driven development" copying sutras starting at the terminal
[Rails] Building an environment for developing web applications
Building an environment for creating apps with Rails and Vue
Use MailHog for checking emails in the development environment (using Docker)
[App development 0.5] [Node.js express Docker] Build an environment for Node.js Express MongoDB using Docker
Procedure for building a Rails application development environment with Docker [Rails, MySQL, Docker]
Build a browser test environment using Capybara in the Docker development environment
Environment construction for Servlet application development
Ruby Study Memo (Test Driven Development)
About the current development environment (Java 8)
Build Java development environment (for Mac)
Building a development environment for Flutter on Win10 --- Flutter SDK Install (2020 preservation version)
Building a Lambda development environment in Eclipse
[Docker] Building an environment to use Hugo
Building a Kotlin development environment using SDKMAN
Prepare the security check environment for Rails 6
[Ruby] Building a Ruby development environment on Ubuntu
Build an Ultra96v2 development environment on Docker 1
Building an environment for WordPress, MySQL and phpMyAdmin with Docker Compose on EC2
[App development 1] [Node.js express Docker] Build an environment for Node.js Express MongoDB (mongoose) using Docker [December 2020]
Procedure for introducing Docker into the development environment of existing Rails applications [Rails, MySQL, Docker]
Introduce Docker to the development environment and test environment of existing Rails and MySQL applications