Quantcast
Channel: Programming Forums
Viewing all articles
Browse latest Browse all 51036

getAllCourses works individually but not as part of test

$
0
0
Hi,

Has been a while and was not sure how to describe my problem.

Basically I built up a program for an assignment from a testharness, all was well testing each part individually till I ran the full test and it fail at my getAllCourses().

The test removes some of my objects from the array then checks the array for a match to required specifications.

Has me a little baffled as all the tests pass individually but not when I run as a whole

Hopefully someone can assist.

GetAllCourses:

public static Course[] getAllCourses() {
           Course[] courses = new Course[courseMap.size()];
           // test line System.out.println(java.util.Arrays.toString(courses));

           int i = 0 ;
           Set<String> courseSet = courseMap.keySet();
           for (Iterator<String> iterator = courseSet.iterator(); 
                   iterator.hasNext();)/>/> {
                   String courseCode = (String)iterator.next();
                   courses[i]= (Course)courseMap.get(courseCode);
                   i++ ;
                  // test line System.out.println(java.util.Arrays.toString(courses));

           }
           if(courses.length>0){
                   return courses;
           }else{
                   return null ;
           }       
        }


the test it fails on

System.out.print("Checking courses with getAllCourses()...");
			if (failureCheck(checkForCourses(model.getAllCourses(), expected),
					true))
				return false;


This is what is happening, not sure if I am removing some of my courses before they make it to this test:

Removing third course with removeCourse()...Removing second course with removeCourse()...Checking courses with getAllCourses()...[null, null]
[COSC1073:Programming 1:12:CORE, null]
[COSC1073:Programming 1:12:CORE, MATH1074:Mathematics for Computing:12:CORE]
 not OK!


A test that is run before this tests printout looks to not affect the structure of my array as it shows it is complete, should I reset the array before I jump to this test or is their another alternative:

Checking courses with getAllCourses()...[null, null, null, null]
[COSC1073:Programming 1:12:CORE, null, null, null]
[COSC1073:Programming 1:12:CORE, MATH1074:Mathematics for Computing:12:CORE, null, null]
[COSC1073:Programming 1:12:CORE, MATH1074:Mathematics for Computing:12:CORE, COSC1076:Programming 2:12:COSC1073:CORE, null]
[COSC1073:Programming 1:12:CORE, MATH1074:Mathematics for Computing:12:CORE, COSC1076:Programming 2:12:COSC1073:CORE, COSC2309:Mobile Application Development:6:COSC1076:ELECTIVE]
 


Hope the above makes sense.

Viewing all articles
Browse latest Browse all 51036

Trending Articles