scala01.idea+junit 搭建scala开发环境

1.idea安装scala插件

scala01.idea+junit 搭建scala开发环境_第1张图片
QQ截图20181119212842.png

2.idea创建Maven项目

scala01.idea+junit 搭建scala开发环境_第2张图片
QQ截图20181119210336.png

3.修改pom.xml文件 整合单元测试框架


        
            org.scala-lang
            scala-library
            2.11.8
            
        
        
        
            org.scalatest
            scalatest_2.11
            3.0.0
            
        
        
            junit
            junit
            4.11
            
        
    
    
        
            
            
                org.scalatest
                scalatest-maven-plugin
                1.0
                
                    ${project.build.directory}/surefire-reports
                    .
                    WDF TestSuite.txt
                
                
                    
                        test
                        
                            test
                        
                    
                
            
        
    

4.添加package,修改项目骨架

scala01.idea+junit 搭建scala开发环境_第3张图片
QQ截图20181119213755.png

5.添加HelloWorld,并测试

object HelloWorld {

    def main(args: Array[String]): Unit = {
        println("hello scala")
    }
}

6.scala编写单元测试的方式1

import org.scalatest.FunSuite

class ScalaJunitTest extends FunSuite {

  //差集
  test("Test difference") {
    val a = Set("a", "b", "a", "c")
    val b = Set("b", "d")
    println(1111111)
    assert(a -- b === Set("a", "c"))
  }

  //交集
  test("Test intersection") {
    val a = Set("a", "b", "a", "c")
    val b = Set("b", "d")
    println(222222)
    assert(a.intersect(b) === Set("b"))
  }

  //并集
  test("Test union") {
    val a = Set("a", "b", "a", "c")
    val b = Set("b", "d")
    println(333333)
    assert(a ++ b === Set("a", "b", "c", "d"))
  }

  test("Test difference1111") {
    val a = Set("a", "b", "a", "c")
    val b = Set("b", "d")
    //应该等于Set("a","b")
    println(444444)
    assert(a -- b === Set("b", "c"))
  }
  test("test123"){
    val a =1;
    val b =3;
    println(12345)
    assert(a==b)
  }
}

7.scala编写单元测试的方式2

import org.junit.{Assert, Test}
@Test
class ScalaClassTest {
  @Test
  def hel:Unit = {
    //scala整合junit进行单元测试 注意必须是class
    //oject 报错
    val someValue = true
    print(111)
    assert(someValue == true)
  }
}

8 项目源码 github地址

https://github.com/code1990/scala.git

你可能感兴趣的:(scala01.idea+junit 搭建scala开发环境)