junit4 - Testing an array of object in Junit, but import can not be resolved -


i trying test if insert function works. eclipse giving me import error. have junit4 in built path. junittest

here solution class

public class solution {      public class interval {         int start;         int end;         interval() { start = 0; end = 0; };         interval(int s, int e) { start = s; end = e; };     }      public static arraylist<interval> insert(arraylist<interval> intervals, interval newinterval) {         // more code 

here solutiontest class

import solution.interval; // error: import solution can't resolved  public class solutiontest {     @before     public void setup() {         arraylist<interval> er = new arraylist<interval>(); //imoprt interval         system.out.println("start");     } 

i suspect problem go away if put code in package other default package. compiler thinks solution package, , cannot find class or interface named interval in solution package.

also, if want able create interval without solution, change interval inner class nested class:

package solution;  public class solution {      public static class interval {         private final int start;         private final int end;          public interval() {           this(0, 0);         }          public interval(int start, int end) {           this.start = start;           this.end = end;         }          ...     }      public static arraylist<interval> insert(list<interval> intervals, interval newinterval) {       ...     } } 

the above class in "src/solution/solution.java"

here test:

package solution;  import solution.solution.interval;  @runwith(junit4.class) public class solutiontest {   private final list<interval> emptyintervallist = new arraylist<interval>();    ... } 

you could, of course, make interval top-level class, if highly recommend putting in different file (named interval.java).

i recommend using the standard maven directory layout.


Comments

Popular posts from this blog

Android : Making Listview full screen -

javascript - Parse JSON from the body of the POST -

javascript - Chrome Extension: Interacting with iframe embedded within popup -