Results 1 to 3 of 3
- 12-31-2009, 12:25 PM #1
Member
- Join Date
- Jul 2009
- Posts
- 21
- Rep Power
- 0
Help please! .class expected when compiling JUnit test?
Hi,
Im fairly new to java programming. I've been given an assignment to write a sorting algorithm and then test it using JUnit tests. The problem is when I try to compile the tester class I get a ".class expected" errors followed by three "; expected" errors for each test method I've written. Any help greatly appreciated!
Here's my tester code:
Java Code:import static org.junit.Assert.*; import org.junit.Test; public class SorterTester{ // Create new sorter object. Sorter sort = new Sorter(); @Test(timeout=15) public void boundaryTest(){ int[] boundaryInts = { 0, 1, -9999, -1, 9999, 10001, 10000, -10000 }; int[] correctBoundarySort = { -10000, -9999, -1, 0, 1, 9999, 10000, 10001 }; assertArrayEquals(int[] correctBoundarySort, int[] sort.sort(boundaryInts)); } /* * Test whether the method can sort correctly when multiple numbers are the * same value */ @Test(timeout=15) public void duplicateSort(){ int[] duplicateInts = { 1, 1, -1, -1, -69, - 69, 0, 0, 0, 1000, 1000 }; int[] correctDuplicateSort = { -69, -69, -1, -1, 0, 0, 0, 1, 1, 1000, 1000}; assertArrayEquals(int[] correctDuplicateSort, int[] sort.sort(duplicateInts)); } /* * Tests does the sorter work when an array of only one digit is passed. */ @Test(timeout=15) public void singleSort(){ int[] singleInt = { 8 }; //Duplicate of singleInt needed because singleInt is always = singleInt int[] correctSingleSort = { 8 }; assertArrayEquals( int[] correctSingleSort, int[] sort.sort( singleInt )); } }
Here's my sorter code:
And here's the error I get:Java Code:public class Sorter{ public void sort( int[] arrayToSort ){ for( int index = 0; index < arrayToSort.length; index++ ){ for( int position = index; position < arrayToSort.length; position++ ){ if( arrayToSort[ position ] < arrayToSort[ index ] ){ int temp = arrayToSort[ index ]; arrayToSort[ index ] = arrayToSort[ position ]; arrayToSort[ position ] = temp; } } } } }
Im sorry if this is somethign really obvious but im stumped, I posted this in another java forum a few days ago but it seems no one could help.Java Code:javac Sorter.java SorterTester.java SorterTester.java:19: '.class' expected assertArrayEquals(int[] correctBoundarySort, int[] sort.sort(boundaryInts)); ^ SorterTester.java:19: ';' expected assertArrayEquals(int[] correctBoundarySort, int[] sort.sort(boundaryInts)); ^ SorterTester.java:19: ';' expected assertArrayEquals(int[] correctBoundarySort, int[] sort.sort(boundaryInts)); ^ SorterTester.java:19: ';' expected assertArrayEquals(int[] correctBoundarySort, int[] sort.sort(boundaryInts)); ^ SorterTester.java:30: '.class' expected assertArrayEquals(int[] correctDuplicateSort, int[] sort.sort(duplicateInts)); ^ SorterTester.java:30: ';' expected assertArrayEquals(int[] correctDuplicateSort, int[] sort.sort(duplicateInts)); ^ SorterTester.java:30: ';' expected assertArrayEquals(int[] correctDuplicateSort, int[] sort.sort(duplicateInts)); ^ SorterTester.java:30: ';' expected assertArrayEquals(int[] correctDuplicateSort, int[] sort.sort(duplicateInts)); ^ SorterTester.java:41: '.class' expected assertArrayEquals( int[] correctSingleSort, int[] sort.sort( singleInt )); ^ SorterTester.java:41: ';' expected assertArrayEquals( int[] correctSingleSort, int[] sort.sort( singleInt )); ^ SorterTester.java:41: ';' expected assertArrayEquals( int[] correctSingleSort, int[] sort.sort( singleInt )); ^ SorterTester.java:41: ';' expected assertArrayEquals( int[] correctSingleSort, int[] sort.sort( singleInt )); ^ 12 errors
Thanks in advance.Last edited by tfitz666; 12-31-2009 at 12:26 PM. Reason: mistake
- 12-31-2009, 12:30 PM #2
Senior Member
- Join Date
- Aug 2009
- Posts
- 2,388
- Rep Power
- 6
In assertArrayEquals(int[] correctBoundarySort, int[] sort.sort(boundaryInts));, you just want to pass the existing arrays not define new ones. You use the
syntax to declare new arrays. To pass the arrays that you have just useJava Code:int[] correctBoundarySort
Java Code:assertArrayEquals(correctBoundarySort, sort.sort(boundaryInts));
- 12-31-2009, 12:45 PM #3
Member
- Join Date
- Jul 2009
- Posts
- 21
- Rep Power
- 0
Similar Threads
-
JUnit Test??? What is it all about????? Please help!!
By nikosa in forum New To JavaReplies: 1Last Post: 08-03-2009, 05:31 PM -
how to use junit for a java class in netbeans
By venkatakrishna.chaithanya in forum New To JavaReplies: 0Last Post: 07-15-2009, 06:41 AM -
JUnit Test Help!
By pharo in forum New To JavaReplies: 0Last Post: 04-10-2009, 05:15 PM -
Junit test
By alice in forum New To JavaReplies: 1Last Post: 06-14-2008, 01:24 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks