Results 1 to 8 of 8
- 10-27-2012, 10:47 PM #1
Member
- Join Date
- Oct 2012
- Posts
- 4
- Rep Power
- 0
Problem compiling and executing to get the JUnit “Green Bar”
I have to use Test Driven development with JUnit and am having trouble getting this code to run and compile. Below is my test and production classes.
Java Code:package edu.hello.test; import junit.framework.*; public class MidtermCourseTest extends TestCase { void testCourse () { Course course = new course ("AAA_AAB", "101"); assertEquals(String "w" , "String "x"); assertEquals("String "y" , "String "z"); } }Java Code:package edu.hello.production; class Course { private String department; Course (String department, String number) { this.department = department; this.number = number; } String getDepartment() { return department;
- 10-28-2012, 01:04 AM #2
Senior Member
- Join Date
- Oct 2012
- Posts
- 108
- Rep Power
- 0
Re: Problem compiling and executing to get the JUnit “Green Bar”
Please include error messages you've received if you want timely help. assertEquals has several signatures, none of which are (String, String). This will use (Object, Object) and probably(I don't have JUnit installed here to verify) not give you the correct results try assertTrue("y".equals("y")) for example.Java Code:assertEquals(String "w" , "String "x"); // Extra double quote ( " ) ... and String should not be here... java expects an Object "w" is a String Object and will be treated accordingly. assertEquals("String "y" , "String "z"); // Two extra double quotes
- 10-28-2012, 02:01 AM #3
Member
- Join Date
- Oct 2012
- Posts
- 4
- Rep Power
- 0
- 10-28-2012, 02:07 AM #4
Senior Member
- Join Date
- Oct 2012
- Posts
- 108
- Rep Power
- 0
Re: Problem compiling and executing to get the JUnit “Green Bar”
Too many '"'. If you see the code blocks above, anything blue is the string, so you've got "w", "String ", "String ", " , ", and "z"
Last edited by SJF; 10-28-2012 at 02:10 AM.
- 10-28-2012, 08:49 AM #5
Member
- Join Date
- Aug 2012
- Posts
- 8
- Rep Power
- 0
Re: Problem compiling and executing to get the JUnit “Green Bar”
Firstly, what do you want to check with this test? I see you have class named Course, and constructor with departmend and number. So maybe something like this:
Java Code:assertEquals(course.getDepartment(), "AAA_AAB"); assertEquals(course.getNumber(), "101"); // " " if number is stored as a String
- 10-28-2012, 03:56 PM #6
Member
- Join Date
- Oct 2012
- Posts
- 4
- Rep Power
- 0
- 10-28-2012, 04:42 PM #7
Member
- Join Date
- Aug 2012
- Posts
- 8
- Rep Power
- 0
Re: Problem compiling and executing to get the JUnit “Green Bar”
Eh why are you writing tests if you don't know very basics of Java?
Java is case sensitive so you can't invoke new course() if you want to invoke new Course().
Additionally, the visibility of Course's constructor and methods is set to default so your test doesn't see them. You have to change it to public.
So:
Java Code:Course course = new Course ("AAA_AAB", "101");Last edited by kuriozal; 10-28-2012 at 04:51 PM.
- 10-28-2012, 05:49 PM #8
Member
- Join Date
- Oct 2012
- Posts
- 4
- Rep Power
- 0
Similar Threads
-
problem with JUnit test
By exltus in forum Advanced JavaReplies: 12Last Post: 12-19-2011, 07:49 PM -
JUnit problem
By SeanC in forum New To JavaReplies: 0Last Post: 01-13-2011, 01:11 AM -
JUnit 4 / JUNIT_HOME Problem
By albertkao in forum EclipseReplies: 0Last Post: 11-22-2010, 09:43 PM -
junit test problem
By moamen in forum EclipseReplies: 2Last Post: 03-14-2010, 09:41 PM -
Help please! .class expected when compiling JUnit test?
By tfitz666 in forum New To JavaReplies: 2Last Post: 12-31-2009, 12:45 PM


LinkBack URL
About LinkBacks
Reply With Quote


Bookmarks