Building an environment for "test-driven development" copying sutras starting at the terminal

Classi Advent Calendar 2017 This is the article on the 13th day. I'm @kasaharu, a front-end engineer. This is the second post for the first time in 12 days.

Recently in-house ["Test Driven Development"](https://www.amazon.co.jp/%E3%83%86%E3%82%B9%E3%83%88%E9%A7%86%E5% 8B% 95% E9% 96% 8B% E7% 99% BA-Kent-Beck / dp / 4274217884) has started a reading party. (It's only once ...) I heard in advance that this book is suitable for sutra copying, so I started with the premise of copying sutras.

At that time, there was one big problem. Yes, no matter what I hide, I don't have an environment where Java runs on my Mac! However, the conflict of not wanting to include an IDE for sutra copying ...

So, today's theme is building an environment for "test-driven development" sutra copying that starts at the terminal!

Insert Java

$ brew tap caskroom/cask
$ brew cask install java
$ java -version
java version "9.0.1"
Java(TM) SE Runtime Environment (build 9.0.1+11)
Java HotSpot(TM) 64-Bit Server VM (build 9.0.1+11, mixed mode)

Insert JUnit

bash_profile


export CLASSPATH=$HOME/sukina/basyo/junit-jupiter-api-5.0.2.jar

Try running the code in Chapter 1

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) {
  }
}
$ javac Dollar.java MoneyTest.java
warning:Unknown enum constant Status.STABLE
Reason: org.apiguardian.api.API$Status class file not found
warning:Unknown enum constant Status.STABLE
2 warnings
$ javac Dollar.java MoneyTest.java
(It's gone!)
$ javac Dollar.java MoneyTest.java
MoneyTest.java:11:error:Can't find symbol
    assertEquals(10, five.amount);
                         ^
symbol:Variable amount
place:Variable of type Dollar five
1 error

Summary

That's why I was ready to copy sutras without having an IDE. I'm going to have a reading party!

Tomorrow is @ spin13! stay tuned!

Recommended Posts

Building an environment for "test-driven development" copying sutras starting at the terminal
Building an environment for copying the book "Test Driven Development"
[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]