Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
:By
Mohammed Ajor
Eslam abu hugair
Mohmmed Alkteeb
JUNIT
JUNIT..
calls setUp()
FIXTURES
FIXTURES
10
11
12
13
TEST SUITES
14
ASSERTX METHODS
assertSame(Objectexpected, Objectactual)
Asserts that two objects refer to the same object (using ==)
assertNotSame(Objectexpected, Objectactual)
assertNull(Objectobject)
15
ASSERTX METHODS
assertNotNull(Objectobject)
fail()
Causes the test to fail and throw an AssertionFailedError
Useful as a result of a complex test, when the other assert
methods arent quite what you want .
16
Create test cases in the same package as the code under test
For each Java package in your application, define a TestSuite
class that contains all the tests for validating the code in the
package
Define similar TestSuite classes that create higher-level and
lower-level test suites in the other packages (and subpackages) of the application
Make sure your build process includes the compilation of all
tests
Unit testing with JUnit
17
JUNIT
FRAMEWORK
Unit testing with JUnit
18
19
20
21
22
}
Unit testing with JUnit
23
TESTCASE LIFECYCLE
1.
2.
3.
4.
setUp
testXXX()
tearDown()
Repeats 1 through 3 for each testXXX
method
24
TEST SUITES
import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;
Demo
import example.SimpleTest;
import example.HtmlDocumentTest;
public class AllTests {
static public Test suite() {
TestSuite suite = new TestSuite();
suite.addTestSuite(SimpleTest.class);
suite.addTestSuite(HtmlDocumentTest.class);
return suite;
}
}
Unit testing with JUnit
25
1.
2.
3.
4.
5.
6.
26
WHY JUNIT
27
ignores:
Programs that do work in response to GUI
commands
Methods that are used primary to produce output
28
29
ANY QUESTIONS?
NO !
THANKS
Unit testing with JUnit
30