[[oktatas:programozás:java:java_teszteles|< Java tesztelés]]
====== Mockito ====
* **Szerző:** Sallai András
* Copyright (c) 2024, Sallai András
* Szerkesztve: 2024
* Licenc: [[https://creativecommons.org/licenses/by-sa/4.0/|CC BY-SA 4.0]]
* Web: https://szit.hu
===== TestNG =====
org.mockito
mockito-testng
0.5.2
org.testng
testng
7.10.2
import static org.mockito.Mockito.when;
import java.util.List;
import org.mockito.Mock;
import org.mockito.testng.MockitoTestNGListener;
import org.testng.Assert;
import org.testng.annotations.Listeners;
import org.testng.annotations.Test;
@Listeners(MockitoTestNGListener.class)
public class MockitoTest {
@Mock
List mockList;
@Test
void mock_list_returns_correct_elements() {
when(mockList.get(0)).thenReturn("foo");
Assert.assertEquals(mockList.get(0), "foo");
}
}
==== Változat 2 ====
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import java.util.List;
import org.testng.Assert;
import org.testng.annotations.Test;
public class MockitoTest {
@Test
void mock_list_returns_correct_elements() {
@SuppressWarnings("rawtypes")
List mockList = mock(List.class);
when(mockList.get(0)).thenReturn("foo");
Assert.assertEquals(mockList.get(0), "foo");
}
}