Hey there, could you guys show the best practices for mocking and testing 1)functional interface 2) method references that are public
@geekific
2 жыл бұрын
Hey! Will keep this in mind for upcoming videos :)
@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
Жыл бұрын
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 :)
Пікірлер: 5