0

I'm trying to do Junit tests on intelliJ but when I run my code I have this error : "Class not found: "xx"". Does someone know how to fix it ?


enter image description here

I run it like that : enter image description here

Here is the code :

import be.ac.ucl.info.javagrading.Grade;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;


import java.io.IOException;
import java.util.*;

import static org.junit.Assert.*;



@RunWith(Parameterized.class)
public class CircularLinkedListTestRandom {
    private CircularLinkedList<Integer> student;
    private List<Integer> correct;


    public CircularLinkedListTestRandom(CircularLinkedList<Integer> student, List<Integer> correct) {
        this.student = student;
        this.correct = correct;
    }

    @Test
    @Grade(value=15)
    public void runAsExpected() {
        Iterator<Integer> aIter = student.iterator();
        Iterator<Integer> bIter = correct.iterator();
        assertEquals(correct.size(),student.size());
        while (bIter.hasNext()) {
            assertTrue(aIter.hasNext());
            assertEquals(bIter.next(),aIter.next());
        }
        assertFalse(bIter.hasNext());
        assertFalse(aIter.hasNext());
    }


    @Parameterized.Parameters
    public static List<Object[]> data() throws IOException {
        Random r = new Random();
        LinkedList tests = new LinkedList<>();
        for (int i = 0; i < 50; i++) {
            CircularLinkedList<Integer> a = new CircularLinkedList<>();
            List<Integer> b = new LinkedList<>();
            for (int k = 0; k < 100; k++) {
                int v = r.nextInt();
                a.enqueue(v);
                b.add(v);
            }
            if (i%2 == 0) {
                a.remove(10);
                b.remove(10);
                a.remove(0);
                b.remove(0);
                a.remove(a.size()-1);
                b.remove(b.size()-1);
            }
            tests.add(new Object[]{a,b});
        }
        return tests;
    }
}

This code is provided by my teacher so it should be correct. It is doing test on the class CircularLinkedList.

Thanks !

Cocoden
  • 1
  • 2
  • 1
    How do you run the code? Please provide the configuration on your IDEA if you have one, or provide the command you run on the console – Alexis Pavlidis Nov 14 '19 at 10:43
  • 1
    Welcome to StackOverflow. Please consider editing your question to include a [Minimal, Complete, Reproducable Example](https://stackoverflow.com/help/minimal-reproducible-example) – hotzst Nov 14 '19 at 10:44
  • 1
    Hey instead of pasting a snap of your code you should paste your code – Nipun Tharuksha Nov 14 '19 at 10:45
  • Does this answer your question? [Running tests on Intellij: Class not found](https://stackoverflow.com/questions/22105264/running-tests-on-intellij-class-not-found) – Andrei Tigau Nov 14 '19 at 10:46
  • @hotzst Thanks for your answer ! I think the code is not the problem here. – Cocoden Nov 14 '19 at 11:03
  • @AlexisPavlidis I run it like that : [enter image description here](https://i.stack.imgur.com/JCEUF.png) – Cocoden Nov 14 '19 at 11:00
  • Can you paste the code please? Unable to access your image. – Hari Rao Nov 14 '19 at 15:22
  • @HariRao Here you are – Cocoden Nov 14 '19 at 16:08
  • I can you have done somethign wrong with importing the project/module. In the project view on your screenshot I can see `LSINF1121_PART1_CircularLinkedList` and `.idea` twice and it shouldn't be the case. However, I am not sure if this is what is causing the problem. – Jaroslaw Pawlak Nov 14 '19 at 16:11
  • @JaroslawPawlak Thanks for your answer but I have already tried to import the project without having two ".idea" and two "LSINF1121_PART1_CircularLinkedList" and it did not work. – Cocoden Nov 14 '19 at 16:15
  • Ok... another thing I can see is that you are using default/unnamed package. Have you tried creating a package and moving your classes into it? – Jaroslaw Pawlak Nov 14 '19 at 16:19
  • @JaroslawPawlak I have just tried and it didn't work – Cocoden Nov 14 '19 at 16:28

0 Answers0