Professional Documents
Culture Documents
OVERVIEW
Page 2
Junit
TABLE OF CONTEXT:
FORWORD
DEFINITION OF TESTING
UNIT TEST
ROLLS
JUNIT
PRINCIPLES OF TEST
TEST METHODE
MY OTHER DOCUMENTATION
Page 3
Junit
Page 4
Junit
Junit
FORWORD
Page 5
Junit
DEFINITION OF TESTING
Page 6
Junit
UNIT TEST
ROLLS
When you want to write your Test-class you should think about
that
-just have one assert per test
-just test one functionallity per test
JUNIT
Page 7
Junit
PRINCIPLES OF TEST
Page 8
Junit
one positive number and 0, and you shouldn’t test all positive
number to each other.
And if you want to test the border on your operation you can
just test with two big integer numbers together.
Example 1
Page 9
Junit
• if (achivedResult == null || !
requiredResult.equals(achivedResult) ) throw new
MyTestyException(“Unexcepted Result");
• With JUnit, you can code import static org.junit.Assert.*; ...
assertEquals(“Unexcepted Result", expectedResults,
requiredResults);
• Every part of junit asserts method throws by
java.lang.AssertionErrors if the test fails.
• You can find lot of various assert depend on your test, here
is just a short list of the whole assert-methods:
• assertArrayEquals
• AssertEquals
• assertFalse
• assertNotNull
• assertNotSame
• assertNull
• assertThat
Page 10
Junit
• assertTrue
• Fails
TEST METHODE
Page 11
Junit
@org.junit.Test
public void testGetPropertyWithReplacements() {
Try{
PropertyManager propManager = new PropertyManager();
propManager.init(); String replacedString =
propManager.getPropertyWithReplacements("text.to.replace",
replacements);
assertTrue(replacedString.indexOf(replacements[0]) > 0); }
catch(Exception e){ AssertionError ae = new AssertionError(
“test Application failed to confirm the properties");
ae.initCause(e); throw ae;
}}
Page 12
Junit
EXAMPLE 3
Import java.lang.*;
Public class StringTest extend AbstractStringTest{
@Test Void testString(){...}
@Test Void testString1(){...}
@Before Void testEqual(){...}
@Before Void testEqual_1(){...}
@After Void testContians(){}
@After Void testContians1(){} }
Page 13
Junit
• .........
• Testcontains()
• TestContains1()
• But the order in the those three groups can changes
• As I saild before the test-methods should be independent to
each other.
• From command line you can very easily use this command •
Java –cp path_to_thte libjunit.jar org.junit.runner.JUnitCore
com.acme.LoadTester yourpackege.yourclass
• From main:
• public static void main(
String args[]) {
org.junit.runner.JUnitCore.main(You rTester.class.getName());
}
Page 14
Junit
Page 15
Junit
<junit>
<classpath refid="classpath.test" />
<formatter type="brief" usefile="false" />
<test name="TestExample" />
</junit>
</target>
Black box testing - Internal system design is not considered in this type of testing. Tests
are based on requirements and functionality.
White box testing - This testing is based on knowledge of the internal logic of an
application’s code. Also known as Glass box Testing. Internal software and code working
Page 16
Junit
should be known for this type of testing. Tests are based on coverage of code statements,
branches, paths, conditions.
Incremental integration testing - Bottom up approach for testing i.e continuous testing
of an application as new functionality is added; Application functionality and modules
should be independent enough to test separately. done by programmers or by testers.
Functional testing - This type of testing ignores the internal parts and focus on the
output is as per requirement or not. Black-box type testing geared to functional
requirements of an application.
System testing - Entire system is tested as per the requirements. Black-box type testing
that is based on overall requirements specifications, covers all combined parts of a
system.
Regression testing - Testing the application as a whole for the modification in any
module or functionality. Difficult to cover all the system in regression testing so typically
automation tools are used for these testing types.
Acceptance testing -Normally this type of testing is done to verify if system meets the
customer specified requirements. User or customer do this testing to determine whether
to accept application.
Page 17
Junit
Load testing - Its a performance testing to check system behavior under load. Testing an
application under heavy loads, such as testing of a web site under a range of loads to
determine at what point the system’s response time degrades or fails.
Stress testing - System is stressed beyond its specifications to check how and when it
fails. Performed under heavy load like putting large number beyond storage capacity,
complex database queries, continuous input to system or database load.
Performance testing - Term often used interchangeably with ’stress’ and ‘load’ testing.
To check whether system meets performance requirements. Used different performance
and load tools to do this.
Usability testing - User-friendliness check. Application flow is tested, Can new user
understand the application easily, Proper help documented whenever user stuck at any
point. Basically system navigation is checked in this testing.
Recovery testing - Testing how well a system recovers from crashes, hardware failures,
or other catastrophic problems.
Security testing - Can system be penetrated by any hacking way. Testing how well the
system protects against unauthorized internal or external access. Checked if system,
database is safe from external attacks or not.
Alpha testing - In house virtual user environment can be created for this type of testing.
Testing is done at the end of development. Still minor design changes may be made as a
result of such testing.
Beta testing - Testing typically done by end-users or others. Final testing before releasing
application for commercial purpose.
Page 18
Junit
Internationalization Testing
API Testing
Some Examples
Listing 1
import junit.framework.TestCase;
import org.junit.Test;
import org.junit.Before;
import dk.unwire.apps.tellafriend.tools.Msisdn;
@Before
public void init() {
this.msisdn = new Msisdn();
}
@Test
public void msisdnStringRightDigitTest() {
this.msisdn = new Msisdn();
assertEquals(true, this.msisdn.IsRightString("123467"));
}
Listing 2
import org.junit.*;
import static org.junit.Assert.*;
import java.util.*;
Page 19
Junit
@BeforeClass
public static void oneTimeSetUp() {
// one-time initialization code
}
@AfterClass
public static void oneTimeTearDown() {
// one-time cleanup code
}
@Before
public void setUp() {
collection = new ArrayList<String>();
}
@After
public void tearDown() {
collection.clear();
}
@Test
public void testEmptyCollection() {
assertTrue(collection.isEmpty());
}
@Test
public void testOneItemCollection() {
collection.add("itemA");
assertEquals(1, collection.size());
}
}
Listing 3
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
* @param args
*/
public static void main(String[] args) {
Pattern p = Pattern.compile("[0-9]*");
Matcher m = p.matcher("121212");
System.out.println( m.matches()+" p3");
}
Page 20
Junit
FEEDBACK
• Please send your feedback/question to
martin_m_nad@yahoo.com
DONATION
Page 21
Junit
My other documentation
Page 22