Mocks vs. Fakes vs. Stubs | Mocking in Java | Mock Frameworks | Geekific

  Рет қаралды 8,463

Geekific

Geekific

Күн бұрын

Пікірлер: 5
@ernaldo1848
@ernaldo1848 3 ай бұрын
Best video by far on the subject
@vijayjayaram606
@vijayjayaram606 2 жыл бұрын
Hey there, could you guys show the best practices for mocking and testing 1)functional interface 2) method references that are public
@geekific
@geekific 2 жыл бұрын
Hey! Will keep this in mind for upcoming videos :)
@skan90
@skan90 Жыл бұрын
These videos are amazing! Congratulations on that! Now I have a small request/question, imagine there's this Java class, a Student and in my tests I need to verify some changes in it made by the method, so I need to initiate the class with some values. How can I instantiate it to be called in the @BeforeEach? Consider I have an Id, Name, and Enums for Gender and Payment Method. Which of the following is the best way (best practice) to do it? (Please, consider that GenderEnum and PaymentMethodEnum are already static imported) _________________________________________________________ (FIST) Student student = new Student ( 1, "John", MALE, CREDIT_CARD) _________________________________________________________ (SECOND) Student student = new Student(); student.setId(1); student.setName("John"); student.setGender(MALE); student.setPaymentMethod(CREDIT_CARD); _________________________________________________________ (THIRD) Student student = Student.builder().id(1).name("John").gender(MALE).paymentMethod(CREDIT_CARD).build(); _________________________________________________________ I would be very glad if could help me, since it's something I did not quite found the answer to yet. Your videos are amazingly good, at my work I've already shared then with friends. Cheers from Brazil. ♥
@geekific
@geekific Жыл бұрын
Hello and thanks a lot for the support! If the student object will not be modified within the specific unit tests (the same object will be used across all tests) then yes it is safe to put it inside the before each one. You can use any of the three options, I personally prefer the third wrapped in a static method. However, if this object will be modified by the units, then I suggest you get rid of the before each entirely and initialize it at the beginning of each unit. Ex: Student student = getStudent(CREDIT_CARD); will be written at the beginning of your unit test as the payment method is what is being tested in that unit for example and that's what needs to be changed. Hope this helps! Cheers :)
Don't Mock 3rd Party Code
19:56
Continuous Delivery
Рет қаралды 39 М.
OYUNCAK MİKROFON İLE TRAFİK LAMBASINI DEĞİŞTİRDİ 😱
00:17
Melih Taşçı
Рет қаралды 8 МЛН
Новый уровень твоей сосиски
00:33
Кушать Хочу
Рет қаралды 4,2 МЛН
Unit Tests and Test Doubles like Mocks, Stubs & Fakes
17:32
Cognitive Programmer
Рет қаралды 134 М.
ТЕСТИРОВАНИЕ НА JAVA (JUNIT, MOCKITO)
9:14
Джавист
Рет қаралды 32 М.
Mocking Asynchronous Functions with Jest
21:50
Swashbuckling with Code
Рет қаралды 70 М.
Mocks, Stubs and Spies with Mockito - JUnit Tutorial
14:59
Aneesh Mistry
Рет қаралды 41 М.
What is Mockito Framework? || Mock your class with Mockito-Junit Framework
39:20
Unit Testing - How to Use Dummies, Fakes, Mocks, and Stubs
11:28