日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

st-lab1

發布時間:2024/4/17 编程问答 26 豆豆
生活随笔 收集整理的這篇文章主要介紹了 st-lab1 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

Junit、Hamcrest、Eclemma的安裝和使用

1.任務要求

Tasks:

  • Install Junit(4.12), Hamcrest(1.3) with Eclipse
  • Install Eclemma with Eclipse
  • Write a java program for the triangle problem and test the program with Junit.
  • a)?????? Description of triangle problem:

    Function triangle takes three integers a,b,c which are length of triangle sides; calculates whether the triangle is equilateral等邊, isosceles等腰, or scalene不等邊.


    2.Install Junit, Hamcrest with Eclipse

       1.Junit

        Eclipse自帶Junit,所以不需要添加jar包,只需要在要使用Junit的project名上,點擊properties-java build path-libraries, 點擊Add library,選擇JunitT即可。

        如圖所示,點擊Add library,在彈出的對話框中選擇Jnuit。

        

      2.Hamcrest?

        在網上查到Eclipse中配置hamcrest的方法與配置Junit的方法一樣,然而在Eclipse的Library中并沒有找到Hamcrest的庫,所以采用添加jar包的方法配置。

  • 從官網下載hamcrest-core.jar;
  • 在要使用Junit的project名上,點擊properties-java build path-libraries, 點擊Add External JARs,把Junit包點上就行了。
  •   3.Eclemma

        1.打開Eclipse,選擇菜單欄“幫助”?-> Eclipse Marketplace,搜索“Eclemma”,結果如圖:

              

        2.點擊安裝即可。


    ?

    ?3.Junit、Hamcrest,Eclemma的使用

      1.Junit測試

    triangle.java:

    1 package triangle; 2 3 import java.util.Scanner; 4 5 public class triangle { 6 public static void main(String[] args) { 7 System.out.println("三角形判斷"); 8 @SuppressWarnings("resource") 9 Scanner reader = new Scanner(System.in); 10 double a=0, b=0, c=0; 11 System.out.printf("輸入a的長度:"); 12 a =reader.nextDouble(); 13 System.out.printf("輸入b的長度:"); 14 b =reader.nextDouble(); 15 System.out.printf("輸入c的長度:"); 16 c =reader.nextDouble(); 17 18 System.out.println(triangle(a,b,c)); 19 } 20 21 public static String triangle(double a,double b,double c) { 22 if(a < b+c&&b < a+c&&c <a+b){ 23 if(a==b&&b==c){ 24 return "The triangle is equilateral."; 25 } 26 else if(a==b||a==c||c==b){ 27 return "The triangle is isosceles."; 28 } 29 else { 30 return "The triangle is scalene."; 31 } 32 33 } 34 else{ 35 return "構不成三角形"; 36 } 37 } 38 39 }

    triangleTest.java:

    1 package triangle; 2 3 import static org.junit.Assert.assertEquals; 4 5 import org.junit.After; 6 import org.junit.Before; 7 import org.junit.Test; 8 9 public class triangleTest { 10 String result; 11 String equilateral="The triangle is equilateral."; 12 String isosceles="The triangle is isosceles."; 13 String scalene="The triangle is scalene."; 14 15 @Before 16 public void setUp() throws Exception { 17 System.out.println("測試開始"); 18 } 19 @After 20 public void tearDown() throws Exception { 21 System.out.println("測試結束..."); 22 } 23 24 @Test 25 public void test1(){ 26 result = triangle.triangle(3,4,5); 27 System.out.println(result); 28 assertEquals(scalene,result); 29 } 30 @Test 31 public void test2(){ 32 result = triangle.triangle(3,3,5); 33 System.out.println(result); 34 assertEquals(isosceles,result); 35 } 36 @Test 37 public void test3(){ 38 result = triangle.triangle(3,3,3); 39 System.out.println(result); 40 assertEquals(equilateral,result); 41 } 42 }

    運行結果:

      2.Eclemma測試結果圖:

    項目覆蓋為44.4%還有待提高。


    ?

    轉載于:https://www.cnblogs.com/jingyizhang/p/8645212.html

    總結

    以上是生活随笔為你收集整理的st-lab1的全部內容,希望文章能夠幫你解決所遇到的問題。

    如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。