2018년 2월 4일 일요일

리눅스 자바 스칼라 설정

# JDK1.8 URL

wget --no-check-certificate --header "Cookie: oraclelicense=accept-securebackup-cookie" http://download.oracle.com/otn-pub/java/jdk/8u112-b15/jdk-8u112-linux-x64.tar.gz

# 디렉토리 생성

mkdir /usr/local/java

# 파일 이동

mv jdk-8u112-linux-x64.tar.gz /usr/local/java

#압축 해제

tar xvzf jdk-8u112-linux-x64.tar.gz

#명령어 등록

alternatives --install /usr/bin/java java /usr/local/java/jdk1.8.0_112/bin/java 1

alternatives --install /usr/bin/java javac /usr/local/java/jdk1.8.0_112/bin/javac 1

alternatives --install /usr/bin/java javaws /usr/local/java/jdk1.8.0_112/bin/javaws 1

alternatives --set java /usr/local/java/jdk1.8.0_112/bin/java

alternatives --set javac /usr/local/java/jdk1.8.0_112/bin/javac

alternatives --set javaws /usr/local/java/jdk1.8.0_112/bin/javaws

#확인

java -version

java version "1.8.0_112"

Java(TM) SE Runtime Environment (build 1.8.0_112-b15)

Java HotSpot(TM) 64-Bit Server VM (build 25.112-b15, mixed mode)

#sbt ( scala build tool ) 설치

wget https://github.com/sbt/sbt/releases/download/v1.1.0/sbt-1.1.0.tgz


# 디렉토리 생성

mkdir /usr/local/sbt

# 파일 이동

mv sbt-1.1.0.tgz /usr/local/sbt

#압축 해제

tar xvzf sbt-1.1.0.tgz


#PATH 설정

vi /etc/profile

export JAVA_HOME=/usr/local/java

export SCALA_HOME=/usr/local/scala

export PATH=$PATH:$JAVA_HOME/bin:$SCALA_HOME/bin

. /etc/profile

# scala 샘플 프로젝트 생성

sbt new scala/scala-seed.g8


#프로젝트 명 생성

scalaTest ( build.sbt )

# 프로젝트 실행

cd scalaTest

sbt test

http://docs.scala-lang.org/getting-started-sbt-track/testing-scala-with-sbt-on-the-command-line.html

Setup

  1. On the command line, create a new directory somewhere.
  2. cd into the directory and run sbt new scala/scala-seed.g8
  3. Name the project ScalaTestTutorial.
  4. The project comes with ScalaTest as a dependency in the build.sbt file.
  5. cd into the directory and run sbt test. This will run the test suiteCubeCalculatorTest with a single test called CubeCalculatorTest.cube.
sbt test
[info] Loading global plugins from /Users/travislee/.sbt/0.13/plugins
[info] Loading project definition from /Users/travislee/workspace/sandbox/my-something-project/project
[info] Set current project to scalatest-example (in build file:/Users/travislee/workspace/sandbox/my-something-project/)
[info] CubeCalculatorTest:
[info] - CubeCalculator.cube
[info] Run completed in 267 milliseconds.
[info] Total number of tests run: 1
[info] Suites: completed 1, aborted 0
[info] Tests: succeeded 1, failed 0, canceled 0, ignored 0, pending 0
[info] All tests passed.
[success] Total time: 1 s, completed Feb 2, 2017 7:37:31 PM

Understanding tests

  1. Open up two files in a text editor:
    • src/main/scala/CubeCalculator.scala
    • src/test/scala/CubeCalculatorTest.scala
  2. In the file CubeCalculator.scala, you’ll see how we define the function cube.
  3. In the file CubeCalculatorTest.scala, you’ll see that we have a class named after the object we’re testing.
  import org.scalatest.FunSuite

  class CubeCalculatorTest extends FunSuite {
      test("CubeCalculator.cube") {
          assert(CubeCalculator.cube(3) === 27)
      }
  }
Let’s go over this line by line.
  • class CubeCalculatorTest means we are testing the object CubeCalculator
  • extends FunSuite lets us use functionality of ScalaTest’s FunSuite class such as the test function
  • test is function that comes from FunSuite that collects results from assertions within the function body.
  • "CubeCalculator.cube" is a name for the test. You can call it anything but one convention is “ClassName.methodName”.
  • assert takes a boolean condition and determines whether the test passes or fails.
  • CubeCalculator.cube(3) === 27 checks whether the output of the cube function is indeed 27. The === is part of ScalaTest and provides clean error messages.

Adding another test case

  1. Add another assert statement after the first one that checks for the cube of 0.
  2. Execute sbt test again to see the results.

Conclusion

You’ve seen one way to test your Scala code. You can learn more about ScalaTest’s FunSuite on the official website. You can also check out other testing frameworks such as ScalaCheck and Specs2.

댓글 없음:

댓글 쓰기