netbeans7.4_NetBeans 7.2引入了TestNG
netbeans7.4
代碼生成的優點之一是能夠查看如何使用特定的語言功能或框架。 正如我在《 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
netbeans7.4
總結
以上是生活随笔為你收集整理的netbeans7.4_NetBeans 7.2引入了TestNG的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: tenda路由器怎么设置网速最大化步骤如
- 下一篇: 老电脑提速三部曲如何让老电脑变快