JUNIT_Test - Project Hosting

Download Report

Transcript JUNIT_Test - Project Hosting

JUNIT Test
Unit and Integration testing
• Implementation Class
• Testing Class
•
•
•
•
•
•
•
•
ConnectionsManager
ChatManager
RosterManager
Timestamps
ConnectionsManagerTest
ChatManagerTest
RosterManagerTest
TimestampsTest
ConnectionsManager.java
• Which is doing work to the XMPP
• This class is the domain connect to the
host. Eg. Should be set to Connect
gmail.com and connect to google.com
• This is to implement the login and logoff
for user by the name and password
ConnectionsManagerTest
•
•
•
•
•
•
•
•
•
•
public void testLogin() {
// legal username with correct password
assertEquals(cm.login("sfu.cmpt275.test1@
gmail.com", "cmpt227755"),
true);
cm.logoff();
// legal username and incorrect password
assertEquals(cm.login("sfu.cmpt275.test1@
gmail.com", "wrong_password"),
false);
•
// illegal username and incorrect password
assertEquals(cm.login("sfu.cmpt275.noexisti
[email protected]",
"wrong_password"), false);
•
•
•
•
// illegal username and incorrect password
assertEquals(cm.login("aaa",
"wrong_password"), false);
}
•
•
•
This is to test bye the login for user
Checking that the name and password both
are correct which user can login
Checking that the name type wrong an
password is correct or the password is
wrong and name is correct that has error
message and both are not correct
ChatManager.java
• Which is to implement the sending
massage
ChatManagerTest.java
• @Test
• public void
testSendMessage() {
• cm.sendMessage("hi
test1",
"sfu.cmpt275.test1@gmai
l.com");
• cm.sendMessage("hi
test2",
"sfu.cmpt275.test2@gmai
l.com");
• }
Which test by two member
set up the name and
password and sent the
get the message and
dirctly by self or other
member
Timestamps.java
• Which set up the time for hour, minutes
and pm/am for current chating
• Which set up the year, month and dates
for current chating
TimestampsTest
•
•
•
•
•
•
•
•
•
•
•
@Test
public void testTheTime() {
String time = Timestamps.theTime();
System.out.println(time);
int hour = Integer.parseInt(time.substring(0, 2));
int min = Integer.parseInt(time.substring(3, 5));
assertEquals(true, (hour >= 0 && hour <= 12));
assertEquals(true, (min >= 0 && min <= 59));
assertEquals(true, (time.substring(6, 8).equalsIgnoreCase("AM") || time
.substring(6, 8).equalsIgnoreCase("PM")));
}
•
•
•
/**
* Test method for
* {@link
javaversion.Assignment3.version1.version1c.syscore.Timestamps#theDate()}
*.
*/
@Test
public void testTheDate() {
String time = Timestamps.theDate();
System.out.println(time);
int day = Integer.parseInt(time.substring(0, 2));
int year = Integer.parseInt(time.substring(5, 9));
assertEquals(true, (day >= 1 && day <= 31));
assertEquals(true, year >= 2009);
assertEquals(true, (time.substring(2, 5).equalsIgnoreCase("Jan")
|| time.substring(2, 5).equalsIgnoreCase("Feb")
|| time.substring(2, 5).equalsIgnoreCase("Mar")
|| time.substring(2, 5).equalsIgnoreCase("Apr")
|| time.substring(2, 5).equalsIgnoreCase("May")
|| time.substring(2, 5).equalsIgnoreCase("Jun")
|| time.substring(2, 5).equalsIgnoreCase("Jul")
|| time.substring(2, 5).equalsIgnoreCase("Aug")
|| time.substring(2, 5).equalsIgnoreCase("Sep")
|| time.substring(2, 5).equalsIgnoreCase("Oct")
|| time.substring(2, 5).equalsIgnoreCase("Nov")
|| time.substring(2, 5).equalsIgnoreCase("Dec")));
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
• Testing the current time for
user to chating
• Test the hour and minutes to
make sure which is integer and
hour has 12 hours and 60
minutes
• Test the dates that has 31
dates each month
• Test the year which must be
bigger than 2009 by user
RosterManagerTest
•
•
•
•
•
•
•
•
•
•
•
•
•
@Before
public void setUp() throws Exception
{
cm = new ConnectionsManager();
cm.login("[email protected]
m", "cmpt227755");
rm = new
RosterManager(cm.getConnection());
}
/**
* @throws java.lang.Exception
*/
@After
public void tearDown() throws
Exception {
cm.logoff();
}
•
•
Testing the connection of automatic
login by roster after the name and
password login
Testing the disconnection of automatic
logoff which is clean up
Integration Testing
IMTest.java
• Test the combined pieces of the system
to see if they work well together
• Testing result: