jUnit test on JAVA fails


k2wln

I'm new here and sorry for the stupid question.

I have some problems with my JUnit test: for some reason it shows me an error in index.html.

I attach the link to my repository through tests and screens.

Thanks! mistake:

org.opentest4j.AssertionFailedError: array contents differ at index [0], 
expected: <Poster(id=3, pictureId=33, filmName=Space, filmGenre=Lamusic)> 
but was: <Poster(id=2, pictureId=22, filmName=Moon, filmGenre=Lamedy)>

Click here to see the test in GitHub

Salmhof

In your second test getLastPosters2()(which doesn't work) you assert a different order than the first test getLastPosters().

Poster[] expected = new Poster[]{thirdFilm,secondFilm};

This is the reverse order, you add it to PosterManager.

Change the order to the following and the test works fine:

Poster[] expected = new Poster[]{secondFilm,thirdFilm};

In your first test getLastPosters()you assert in the same order as you add them to PosterManager.

However, either your second test asserts the wrong order and fails, or your implementation is wrong and your first test is a "false positive".

Related


junit test fails with exception

Sebastian Dietrich I am using junit to test my Metrics class. When the test runs, I don't get any exceptions, but the test doesn't succeed. I've tried to find all the different questions but haven't found any. Here is its code. public class MetricsTest { pri

Spring JUnit test case fails

Misco I try to run a JUnit test case for a ProductDAOclass , which is part of a Spring web application. But it still fails. I am not sure about my test-context.xml file. I have a class ProductDAOImplTestin path src/test/javaand the class mentioned ProductContr

Spring JUnit test case fails

Misco I try to run a JUnit test case for a ProductDAOclass , which is part of a Spring web application. But it still fails. I am not sure about my test-context.xml file. I have a class ProductDAOImplTestin path src/test/javaand the class mentioned ProductContr

Spring JUnit test case fails

Misco I try to run a JUnit test case for a ProductDAOclass , which is part of a Spring web application. But it still fails. I am not sure about my test-context.xml file. I have a class ProductDAOImplTestin path src/test/javaand the class mentioned ProductContr

sbt assembly with Junit test fails

3nomis I am very new to Scala and sbt. I want to run Junit tests with sbt assembly. I have all my tests designed and run correctly using IntelliJ. When I try to build with test it always fails and gives a lot of errors. Here is my build.sbt name := "updater" v

sbt assembly with Junit test fails

3nomis I am very new to Scala and sbt. I want to run Junit tests with sbt assembly. I have all my tests designed and run correctly using IntelliJ. When I try to build with test it always fails and gives a lot of errors. Here is my build.sbt name := "updater" v

Run a method if the test fails on Junit

Keva 161 I've added a method to my Selenium framework that takes a screenshot at the end of a test, but it doesn't run all the way to the end because some tests fail. I want to implement a rule to run this screenshot method if the test fails. It's just like: @

Spring JUnit test case fails

Misco I try to run a JUnit test case for a ProductDAOclass , which is part of a Spring web application. But it still fails. I am not sure about my test-context.xml file. I have a class ProductDAOImplTestin path src/test/javaand the class mentioned ProductContr

JUnit exception test fails (unexpectedly)

Simon I'm trying to run a JUnit test to test a method that will throw an exception. However, the test fails and I don't know why. The method that throws the exception is: calcultor.setN();. I made two versions of this test and both failed, although they should

JUnit exception test fails (unexpectedly)

Simon I'm trying to run a JUnit test to test a method that will throw an exception. However, the test fails and I don't know why. The method that throws the exception is: calcultor.setN();. I made two versions of this test and both failed, although they should

Spring JUnit test case fails

Misco I try to run a JUnit test case for a ProductDAOclass , which is part of a Spring web application. But it still fails. I am not sure about my test-context.xml file. I have a class ProductDAOImplTestin path src/test/javaand the class mentioned ProductContr

JUnit exception test fails (unexpectedly)

Simon I'm trying to run a JUnit test to test a method that will throw an exception. However, the test fails and I don't know why. The method that throws the exception is: calcultor.setN();. I made two versions of this test and both failed, although they should

JUnit Mockito test fails with equalTo

dreamer I'm trying to understand why adding equalTo fails my test. I have recreated the question with a simple class and test. The first test passed, the second failed. sample lesson public class Class { Map<String, Boolean> data = new HashMap<>(); public Ma

Java Junit test problem

User238384: I am using Junit4. My whole program works fine. I am trying to write a test case. But there is an error... This is very basic sample test public class di extends TestCase{ private static Records testRec; public void testAbc() { Ass

Java - JUnit Test - ArrayList

store code I wrote a class to find files into directories and subdirectories: public class DirectoryWalker { public List<File> walk(String path) { File root = new File(path); List<File> resultList = new ArrayList<>(); File[] list

Java Junit test problem

User238384: I am using Junit4. My whole program works fine. I am trying to write a test case. But there is an error... This is very basic sample test public class di extends TestCase{ private static Records testRec; public void testAbc() { Ass

Java - JUnit Test - ArrayList

store code I wrote a class to find files into directories and subdirectories: public class DirectoryWalker { public List<File> walk(String path) { File root = new File(path); List<File> resultList = new ArrayList<>(); File[] list

Java - JUnit Test - ArrayList

store code I wrote a class to find files into directories and subdirectories: public class DirectoryWalker { public List<File> walk(String path) { File root = new File(path); List<File> resultList = new ArrayList<>(); File[] list

Java Comparator JUnit Test

weary How to use JUnit test to test the following class. I'm new to unit testing and I just need to push public class ComponentComparator implements Comparator< Component > { @Override public int compare ( final Component c1, final Component c2 ) { if ( c

JUnit test for Java Comparator

weary How to use JUnit test to test the following class. I'm new to unit testing and I just need to push to get started public class ComponentComparator implements Comparator< Component > { @Override public int compare ( final Component c1, final Component c2

Java Junit test problem

User238384: I am using Junit4. My whole program works fine. I am trying to write a test case. But there is an error... This is very basic sample test public class di extends TestCase{ private static Records testRec; public void testAbc() { Ass

Java - JUnit Test - ArrayList

store code I wrote a class to find files into directories and subdirectories: public class DirectoryWalker { public List<File> walk(String path) { File root = new File(path); List<File> resultList = new ArrayList<>(); File[] list

Java - JUnit Test - ArrayList

store code I wrote a class to find files into directories and subdirectories: public class DirectoryWalker { public List<File> walk(String path) { File root = new File(path); List<File> resultList = new ArrayList<>(); File[] list

Java - JUnit Test - ArrayList

store code I wrote a class to find files into directories and subdirectories: public class DirectoryWalker { public List<File> walk(String path) { File root = new File(path); List<File> resultList = new ArrayList<>(); File[] list

Java - JUnit Test - ArrayList

store code I wrote a class to find files into directories and subdirectories: public class DirectoryWalker { public List<File> walk(String path) { File root = new File(path); List<File> resultList = new ArrayList<>(); File[] list

JUnit test for Java Comparator

weary How to use JUnit test to test the following class. I'm new to unit testing and I just need to push to get started public class ComponentComparator implements Comparator< Component > { @Override public int compare ( final Component c1, final Component c2

Java Junit for property class fails

rogue I have Mappa class which has mappaName as property (can be selected from enum names) and also a method getMappaName which returns it and when i run test to compare one of mappaName selected from Name i get expected FERMI , but is: null public class M

Java Junit for property class fails

rogue I have Mappa class which has mappaName as property (can be selected from enum names) and also a method getMappaName which returns it and when i run test to compare one of mappaName selected from Name i get expected FERMI , but is: null public class M

JUnit-Mockito test fails with InvalidUseOfMatchersException

Nital : I'm having trouble building the when-thentest part . I am getting the following error when running the test. I've looked into this SO link ( Mockito: InvalidUseOfMatchersException ) and refactored my code to use, eq()but still the same error. mistake: