So I'm trying to implement Mockito and JUnit5, but I can't seem to make it work. It always shows this error:
This is the test file:
package test;
import static org.junit.jupiter.api.Assertions.*;
import static org.mockito.Mockito.*;
import javax.swing.*;
import java.util.*;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.junit.jupiter.MockitoExtension;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import com.mycompany.helloworldapp.Activity1;
import utils.TestUtils;
@ExtendWith(MockitoExtension.class)
public class Activity1Test {
@InjectMocks
Activity1 activity1;
@Mock
List<Integer> list;
@Test
public void testUpdateTextButton() {
when(list.add(100)).thenReturn(true);
}
}
Libraries used:
- junit-platform-console-standalone-1.8.2
- mockito-core-4.1.0
- mockito-junit-jupiter-4.1.0
This is the folder structure:
And these are the commands I used in the Terminal:
1. Compiling Java files except Test files:
cd src; javac -target 17 -source 17 com/mycompany/helloworldapp/Activity1.java
cd src; javac -target 17 -source 17 utils/TestUtils.java
2. Compiling Test files:
cd src; javac -target 17 -source 17 -sourcepath . -classpath libraries/JUnit-Standalone.jar:libraries/Mockito-Core.jar:libraries/Mockito-JUnit-Jupiter.jar test/Activity1Test.java
3. Running the test:
cd src; java -jar libraries/JUnit-Standalone.jar --classpath . --scan-classpath