Date post: | 07-Aug-2015 |
Category: |
Technology |
Upload: | lim-sim |
View: | 165 times |
Download: | 1 times |
What are we going to learn● Setting up a test project from scratch● How to write a test using JUnit● How to write a test using TestNG
Common terminology● Test suite● Test class● Test● Before and After test hooks
○ class○ test
● Assertions
What to test against● The world famous calculator program● Get the code from Github
○ git clone [email protected]:limsim/intro-to-java-test-frameworks-start.git
Different ways of running test● From command line run mvn test● Use IDE ● (You could use Java and JUnit but the
command is long and not user friendly)
TestAdd JUnit dependency to Maven <dependencies> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.12</version> <scope>test</scope> </dependency> </dependencies>
Make an assertionpublic class CalculatorTest{
@Testpublic void
addReturnsSumOfTwoNumbers() {Assert.assertEquals("Fail!", 1,
new Calculator().add(1, 1));}
}
ExcerciseTry writing tests to do the following● Use assertTrue to check that expected and
actual results from add() are the same.● Use assertFalse to check that expected and
actual results from add() are not the same.● Use assertNotNull to check that Calculator has
been created.
Generate HTML reportsNeed to add a reporting plugin<reporting> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-surefire-report-plugin</artifactId> <version>2.18.1</version> </plugin> </plugins> </reporting>
TestNGAdd TestNG dependency <dependencies> <dependency> <groupId>org.testng</groupId> <artifactId>testng</artifactId> <version>6.8.8</version> <scope>test</scope> </dependency> </dependencies>