professional documents
home
Upload
docsters
Upload
about me
contact me
user photo
mike shinoda
student
MR
IT specialist
If u like these docs or they are helpful to you just say thanks, and if you want any document or any book + courses[actualtests.com] or from any other site just send me a message i will try my best to help you.
submit clear
Powerpoint

JUnit Tutorial center doc

JUnit TutorialHong Qing YuNov 20052JUnit TutorialThe testing problemsThe framework of JUnitA case studyJUnit toolPractices3The Testing ProblemsprogrammersShould writefewDoWhy?I am so busyIt is difficult4The Testing ProblemsProgrammers need such kind of tool:“Writing a few lines of code, then a test that should run, or even better, to write a test that won't run, then write the code that will make it run.”JUnit is that kind of tool!5JUnit TutorialThe testing problems The framework of JUnitA case studyJUnit toolPractices6The Framework of JUnit7JUnit TutorialThe testing problemsThe framework of JUnitA case studyJUnit toolPractices8A Case Studyclass Money { private int fAmount; private String fCurrency;public Money(int amount, String currency) { fAmount= amount; fCurrency= currency; }public int amount() { return fAmount; }public String currency() { return fCurrency; }public Money add(Money m) { return new Money(amount()+m.amount(), currency()); }}9How to Write A TestCasepublic class MoneyTest extends TestCase { //… public void testSimpleAdd() { Money m12CHF= new Money(12, "CHF");//(1) Money m14CHF= new Money(14, "CHF");Money expected= new Money(26, "CHF");Money result= m12CHF.add(m14CHF);//(2)Assert.assertTrue(expected.equals(result));//(3) } }(1) Creates the objects we will interact with during the test. This testing context is commonly referred to as a test'sfixture. All we need for the testSimpleAdd test are some Money objects.(2) Exercises the objects in the fixture. (3) Verifies the result 10AssertassertEquals(expected, actual) assertEquals(message, expected, actual) assertEquals(expected, actual, delta)assertEquals(message, expected, actual, delta) assertFalse(condition) assertFalse(message, condition) Assert(Not)Null(object) Assert(Not)Null(message, object) Assert(Not)Same(expected, actual) Assert(Not)Same(message, expected, actual) assertTrue(condition) assertTrue(message, condition) 11Structure setUp()Storing the fixture's objects in instance variables of your TestCasesubclass and initialize them by overriding the setUp method tearDown()Releasing the fixture’srun() Defining how to run an individual test case.Defining how to run a test suite.testCase()12Structure of Writing A Test public class MoneyTest extends TestCase { private Money f12CHF; private Money f14CHF;protected void setUp() { f12CHF= new Money(12, "CHF"); f14CHF= new Money(14, "CHF"); }public void testSimpleAdd() { Money expected= new Money(26, "CHF"); Money result= f12CHF.add(f14CHF); Assert.assertTrue(expected.equals(result)); }TestCase test= new MoneyTest("simple add") { public void runTest() { testSimpleAdd(); } }}13Design Test CasesThe real world scenariosThe number boundariesSmaller than 0 such as –1, -2, …, -100, …0Bigger than 0 such as 1, 2, …, 100…14The Feedback to Codeclass Money { private int fAmount; private String fCurrency;public Money(int amount, String currency) { fAmount= amount; fCurrency= currency; }public int amount() { return fAmount; }public String currency() { return fCurrency; }public Money add(Money m) {if (m.amount()<=0) throw exception;return new Money(amount()+m.amount(), currency()); }}15Test Case and Test SuiteTestCase test= new MoneyTest("simple add"){ public void runTest() { testSimpleAdd(); } }public static Test suite() { TestSuite suite= new TestSuite(); suite.addTest(new MoneyTest("testEquals")); suite.addTest(new MoneyTest("testSimpleAdd")); return suite; }16Static and Dynamic RunJUnit supports two ways of running single tests: 1.static 2.dynamic TestCase test= new MoneyTest("simple add"){ public void runTest() { testSimpleAdd(); } }TestCase test= new MoneyTest("testSimpleAdd");Since JUnit 2.0 there is an even simpler dynamic way. You only pass the class with the tests to a TestSuite and it extracts the test methods automatically. public static Test suite() {return new TestSuite(MoneyTest.class); } 17JUnit TutorialThe testing problemsThe framework of JUnitA case studyJUnit toolPractices18JUnit19JUnit for Eclipse20Start to Use it1. Download the latest version of JUnit from http://download.sourceforge.net/junit/2. Installationunzip the junit.zip file addjunit.jarto the CLASSPATH. For example: set classpath=%classpath%;INSTALL_DIR\junit3\junit.jar 3. TestingTest the installation by using either the batch or the graphical TestRunner tool to run the tests that come with this release. All the tests should pass OK. for the batch TestRunner type: java junit.textui.TestRunner junit.samples.AllTests for the graphical TestRunner type: java junit.awtui.TestRunner junit.samples.AllTests for the Swing based graphical TestRunner type: java junit.swingui.TestRunner junit.samples.AllTestsNotice: The tests are not contained in the junit.jar but in the installation directory directly. Therefore make sure that the installation directory is on the class pathImportant: Don't install the junit.jar into the extension directory of your JDK installation.If you do so the test class on the files system will not be found. JUnit plug-in for Eclipse21Eclipse plug-inhttp://dev.eclipse.org/viewcvs/index.cgi/jdt-ui-home/plugins/org.eclipse.jdt.junit/org.eclipse.pde.junit_3.0.0.zip22The testing problemsThe framework of JUnitA case studyJUnit toolPractices23PracticesBankAccount case study24More Readinghttp://www.junit.org/index.htmhttp://open.ncsu.edu/se/tutorials/junit/http://www.cs.umanitoba.ca/~eclipse/10-JUnit.pdfhttp://supportweb.cs.bham.ac.uk/documentation/tutorials/docsystem/build/tutorials/junit/junit.pdfhttp://junit.sourceforge.net/javadoc/junit/framework/25Contact informationhqy1@le.ac.ukToday’s slides can be find at http://www.cs.le.ac.uk/people/hqy1/JUnit%20Tutorial.ppt26Thanks And Questions
rate this doc
email this doc
embed this doc
add to folder
digg reddit stumble delicious
flag this doc
1027
10
not rated
0
11/20/2007
English

Preview

LEARN

ravenms 11/20/2007 | 184 | 6 | 0 | educational
Preview

Tutorial_MCP_final

ravenms 11/20/2007 | 153 | 3 | 0 | educational
Preview

Active Learning - Motivating Students to Learn

ravenms 11/20/2007 | 288 | 60 | 0 | educational
Preview

FANS 1.8 learning how to learn

ravenms 11/20/2007 | 420 | 47 | 0 | educational
Preview

brain-learn

ravenms 11/20/2007 | 484 | 81 | 0 | educational
Preview

Games to Learn

ravenms 11/20/2007 | 312 | 9 | 0 | educational
Preview

lerqaning to learn

ravenms 11/20/2007 | 131 | 2 | 0 | educational
Preview

lunch-and-learn

ravenms 11/20/2007 | 181 | 4 | 0 | educational
Preview

structure-learn

ravenms 11/20/2007 | 195 | 3 | 0 | educational
Preview

Asking-Users-to-Learn

ravenms 11/20/2007 | 206 | 5 | 0 | educational
Preview

B15_Keynote_Interprofessional_and_m ultiprofessional_learn

ravenms 11/20/2007 | 159 | 1 | 0 | educational
Preview

Data+Mining+Lunch+and+Learn

ravenms 11/20/2007 | 243 | 9 | 0 | educational
Preview

FPU-Lunch and Learn

ravenms 11/20/2007 | 169 | 2 | 0 | educational
Preview

Helping students learn

ravenms 11/20/2007 | 319 | 34 | 0 | educational
Preview

teaching_how_2_ learn

ravenms 11/20/2007 | 206 | 6 | 0 | educational
Preview

Addison.Wesley.Pub.Exploiting.Softw are.How.to.Break.Code.eBook-kB

ravenms 6/17/2008 | 277 | 21 | 0 |
Preview

The First Christian Historian

ravenms 4/5/2008 | 407 | 9 | 0 |
Preview

The Cambridge Companion to American Women Playwrights

ravenms 4/5/2008 | 413 | 4 | 0 |
Preview

Shakespeare and the Origins of English

ravenms 4/5/2008 | 76 | 6 | 0 |
Preview

Restall - Logic

ravenms 4/5/2008 | 226 | 7 | 0 |
Preview

Learning to Teach History in the Primary School

ravenms 4/5/2008 | 327 | 7 | 0 |
Preview

Celibacy and Religious Traditions

ravenms 4/5/2008 | 80 | 2 | 0 |
Preview

10 ways to say i love u

ravenms 4/4/2008 | 546 | 53 | 0 |
Preview

O'Reilly - Core JSP _2000_

ravenms 3/5/2008 | 842 | 28 | 0 |
Preview

O'Reilly - COM and .Net Component Services

ravenms 3/5/2008 | 86 | 1 | 0 |
 
review this doc