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

歡迎訪問 生活随笔!

生活随笔

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

编程问答

NetBeans 7.2引入了TestNG

發布時間:2023/12/3 编程问答 43 豆豆
生活随笔 收集整理的這篇文章主要介紹了 NetBeans 7.2引入了TestNG 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
代碼生成的優點之一是能夠查看如何使用特定的語言功能或框架。 正如我在《 NetBeans 7.2 beta:更快,更有用》一文中所討論的那樣, NetBeans 7.2 beta提供了TestNG集成 。 除了對該功能的單一引用之外,我在該帖子中沒有進一步闡述,因為我想將這篇帖子專門用于該主題。 我使用這篇文章來演示如何使用NetBeans 7.2來幫助剛接觸TestNG的開發人員開始使用該替代(對JUnit )測試框架。

NetBeans 7.2的“新建文件”向導使創建空的TestNG測試用例更加容易。 以下屏幕快照展示了這一點,該屏幕快照是使用“新建文件” |“開始”按鈕啟動的。 單元測試(請注意,在“文件”下拉菜單下或通過在“項目”窗口中單擊鼠標右鍵可以使用“新文件”)。

如上所示運行TestNG測試用例創建將導致以下生成的測試代碼。

TestNGDemo.java(由NetBeans 7.2生成)

package dustin.examples;import org.testng.annotations.AfterMethod; import org.testng.annotations.AfterClass; import org.testng.annotations.BeforeMethod; import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; import org.testng.Assert;/**** @author Dustin*/ public class TestNGDemo { public TestNGDemo(){}@BeforeClasspublic void setUpClass(){}@AfterClasspublic void tearDownClass(){}@BeforeMethodpublic void setUp(){}@AfterMethodpublic void tearDown(){}// TODO add test methods here.// The methods must be annotated with annotation @Test. For example://// @Test// public void hello() {} }

NetBeans 7.2生成的測試包含注釋,這些注釋指示如何添加和注釋測試方法(類似于現代版本的JUnit)。 生成的代碼還顯示了一些注釋,用于整體測試用例的設置和拆卸以及針對每次測試的設置和拆卸(注釋與JUnit相似)。 NetBeans標識此時尚未使用的import語句( import org.testng.annotations.Test;和import org.testng.Assert; ),但是可能被使用,因此已包含在生成的代碼中。

我可以輕松地將測試方法添加到此生成的測試用例中。 以下代碼段是使用TestNG的測試方法。

testIntegerArithmeticMultiplyIntegers()

@Testpublic void testIntegerArithmeticMultiplyIntegers(){final IntegerArithmetic instance = new IntegerArithmetic();final int[] integers = {4, 5, 6};final int expectedProduct = 2 * 3 * 4 * 5 * 6;final int product = instance.multiplyIntegers(2, 3, integers);assertEquals(product, expectedProduct);}

當然,這看起來與我在測試Invalidgerquals with JUnit and Hamcrest和JUnit的內置Hamcrest Core Matcher Support文章中的插圖所使用的IntegerArithmetic類所使用的同一個IntegerArithmetic類中使用的JUnit類似。 以下屏幕快照顯示了通過右鍵單擊測試用例類并選擇“運行文件”(Shift + F6),在NetBeans 7.2 beta中的輸出。

接下來,將復制NetBeans 7.2 beta中提供的TestNG運行的文本輸出。

[TestNG] Running:Command line suite[VerboseTestNG] RUNNING: Suite: "Command line test" containing "1" Tests (config: null) [VerboseTestNG] INVOKING CONFIGURATION: "Command line test" - @BeforeClass dustin.examples.TestNGDemo.setUpClass() [VerboseTestNG] PASSED CONFIGURATION: "Command line test" - @BeforeClass dustin.examples.TestNGDemo.setUpClass() finished in 33 ms [VerboseTestNG] INVOKING CONFIGURATION: "Command line test" - @BeforeMethod dustin.examples.TestNGDemo.setUp() [VerboseTestNG] PASSED CONFIGURATION: "Command line test" - @BeforeMethod dustin.examples.TestNGDemo.setUp() finished in 2 ms [VerboseTestNG] INVOKING: "Command line test" - dustin.examples.TestNGDemo.testIntegerArithmeticMultiplyIntegers() [VerboseTestNG] PASSED: "Command line test" - dustin.examples.TestNGDemo.testIntegerArithmeticMultiplyIntegers() finished in 12 ms [VerboseTestNG] INVOKING CONFIGURATION: "Command line test" - @AfterMethod dustin.examples.TestNGDemo.tearDown() [VerboseTestNG] PASSED CONFIGURATION: "Command line test" - @AfterMethod dustin.examples.TestNGDemo.tearDown() finished in 1 ms [VerboseTestNG] INVOKING CONFIGURATION: "Command line test" - @AfterClass dustin.examples.TestNGDemo.tearDownClass() [VerboseTestNG] PASSED CONFIGURATION: "Command line test" - @AfterClass dustin.examples.TestNGDemo.tearDownClass() finished in 1 ms [VerboseTestNG] [VerboseTestNG] =============================================== [VerboseTestNG] Command line test [VerboseTestNG] Tests run: 1, Failures: 0, Skips: 0 [VerboseTestNG] ============================================================================================== Command line suite Total tests run: 1, Failures: 0, Skips: 0 ===============================================Deleting directory C:\Users\Dustin\AppData\Local\Temp\dustin.examples.TestNGDemo test: BUILD SUCCESSFUL (total time: 2 seconds)

上面的示例顯示了開始使用TestNG是多么容易,特別是如果從JUnit遷移到TestNG并正在使用NetBeans 7.2 beta。 當然,還有更給TestNG的不是這個,而是學習一個新的框架通常是最困難的,在開始和NetBeans 7.2得到一個開了一個快速啟動。

參考: NetBeans 7.2在Inspired by Actual Events博客中從JCG合作伙伴 Dustin Marx 引入了TestNG 。


翻譯自: https://www.javacodegeeks.com/2012/06/netbeans-72-introduces-testng.html

總結

以上是生活随笔為你收集整理的NetBeans 7.2引入了TestNG的全部內容,希望文章能夠幫你解決所遇到的問題。

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