This video and this channel deserve atleast 3 zeros more in the amount of likes and subscribers...
@sasherazi19 күн бұрын
top quality content
@AneeshMistry16 күн бұрын
Thank you so much!
@akashg986320 күн бұрын
Your have arranged the content very well. The definitions are easy with good examples. I haven't got a chance to use Spy in real world. Thanks for creating this. I will recommend this and the previous video as a starter for anyone who is new to Mockito.
@AneeshMistry16 күн бұрын
Thank you so much! It means a lot to me, I am glad it helped
@Leo-cw6dr26 күн бұрын
Thank you for the video! Looking forward to seeing more!!!
@AliN-s4fАй бұрын
This is such a great video
@AneeshMistry16 күн бұрын
Thank you!
@JamesBrown-lq5nnАй бұрын
Direct, simple and on the money, love it!!
@beninipАй бұрын
I was struggling with that concept for months. I couldn't grasp it, luckily I came across this video. Now, it's clear than ever, clear and simple explaination. Good job!
@hftconsultancyАй бұрын
Please do continue
@AA-em3lwАй бұрын
great job (= Thank you for this short and practical video!
@1More_Dreamer2 ай бұрын
Bro just expanded my intelect 😅
@Luizanbrg2 ай бұрын
thank you so much! your voice is super smooth and the explanation is very clear
@user-fl3of4pv7s2 ай бұрын
Excellent and simple explanation. Many thanks. You have great future ahead.
@rastemmilengephirchltechlte2 ай бұрын
One video for rest api with external api testing
@zahirulislam20973 ай бұрын
It was easy to follow. Thank you. Very good video on this topic.
@saveUyghurs3 ай бұрын
Had to watch multiple times to understand
@Jim-gr5uy3 ай бұрын
This is great Aneesh thanks a lot, teeing has been driving me made so this has helped! Cheers
@AneeshMistry3 ай бұрын
Thank you!
@HimanshuKumar-ow7hw3 ай бұрын
CHATGPT: Updated PlayerStatisticsTest Class (JUnit 5) import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import static org.assertj.core.api.Assertions.assertThat; import static org.junit.jupiter.api.Assertions.assertThrows; public class PlayerStatisticsTest { private Player playerPatrickUnderThirty; private PlayerStatistics statisticsOfPatrickUnderThirty; @BeforeEach public void setup() { playerPatrickUnderThirty = new Player("Patrick", 27); statisticsOfPatrickUnderThirty = new PlayerStatistics(playerPatrickUnderThirty, 3, 3); } @Test @DisplayName("Player names should be equal") public void playerNameEqual() { Player player2 = new Player("Patrick", 25); assertThat(player2).isEqualTo(playerPatrickUnderThirty); } @Test @DisplayName("Player names should not be equal") public void playerNamesNotEqual() { Player player2 = new Player("Kalvin", 25); assertThat(player2).isNotEqualTo(playerPatrickUnderThirty); } @Test @DisplayName("Get the younger player when ages are different") public void youngerPlayerSame() { Player player2 = new Player("Patrick", 250); assertThat(PlayerStatistics.getYoungerPlayer(playerPatrickUnderThirty, player2)).isSameAs(playerPatrickUnderThirty); } @Test @DisplayName("Check if player is under thirty") public void underThirtyTrue() { assertThat(statisticsOfPatrickUnderThirty.underThirty()).isTrue(); } @Test @DisplayName("Check if player is not under thirty") public void underThirtyFalse() { Player player1 = new Player("Patrick", 37); PlayerStatistics statistics = new PlayerStatistics(player1, 3, 3); assertThat(statistics.underThirty()).isFalse(); } @Test @DisplayName("CSV Report should return null when games are zero") public void csvReportNull() { PlayerStatistics statistics = new PlayerStatistics(playerPatrickUnderThirty, 0, 0); assertThat(statistics.createCsvRecord()).isNull(); } @Test @DisplayName("CSV Report should not be null when games are greater than zero") public void csvReportNotNull() { PlayerStatistics statistics = new PlayerStatistics(playerPatrickUnderThirty, 3, 3); assertThat(statistics.createCsvRecord()).isNotNull(); } @Test @DisplayName("Get correct CSV stats record") public void getCsvStatsRecord() { PlayerStatistics statistics = new PlayerStatistics(playerPatrickUnderThirty, 4, 8); Double[] expectedArray = {2d, 0.5}; assertThat(statistics.createCsvRecord()).isEqualTo(expectedArray); } @Test @DisplayName("PlayerStatistics constructor should throw exception for null player") public void playerStatisticsConstructorThrowsExceptionForNullPlayer() { assertThrows(IllegalArgumentException.class, () -> { new PlayerStatistics(null, 3, 2); }); } @Test @DisplayName("PlayerStatistics constructor should throw exception for negative games") public void playerStatisticsConstructorThrowsExceptionForNegativeGames() { Player player = new Player("Patrick", 27); assertThrows(IllegalArgumentException.class, () -> { new PlayerStatistics(player, -1, 2); }); } @Test @DisplayName("PlayerStatistics constructor should throw exception for negative goals") public void playerStatisticsConstructorThrowsExceptionForNegativeGoals() { Player player = new Player("Patrick", 27); assertThrows(IllegalArgumentException.class, () -> { new PlayerStatistics(player, 3, -1); }); } } The @DisplayName annotation in JUnit 5 is used to specify a custom name or description for a test method. This custom name is displayed when the test results are reported, making it easier to understand the purpose of each test at a glance. Example Usage Here’s a quick example of how you might use @DisplayName: --------------------------------------------------------------------------------------------------------------- import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; public class ExampleTest { @Test @DisplayName("Should return true when the input is valid") void testValidInput() { // test code here } @Test @DisplayName("Should throw an exception for invalid input") void testInvalidInput() { // test code here } } Output When running these tests, the output will show the display names instead of just the method names, which provides clearer context on what each test is meant to verify: - Should return true when the input is valid Should throw an exception for invalid input -
@HimanshuKumar-ow7hw3 ай бұрын
CHATGPT: RaceReportProcessorTest class converted to JUnit 5: import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertTrue; import static com.googlecode.catchexception.CatchException.catchException; import java.io.FileNotFoundException; public class RaceReportProcessorTest { private RaceReportProcessor reportProcessor; @BeforeEach public void setUp() { reportProcessor = new RaceReportProcessor(); } @AfterEach public void tearDown() { // Clean up temp files if created } @Test public void generateReportDriverFileThrowsFileNotFound() throws Exception { String driverFile = "drivers/drivers.csv"; String raceFile = "racePerformance/race.csv"; catchException(reportProcessor).generateReport(driverFile, raceFile); assertTrue(caughtException() instanceof FileNotFoundException); assertEquals("drivers/drivers.csv (No such file or directory)", caughtException().getMessage()); } @Test public void generateReportRaceFileThrowsFileNotFound() throws Exception { String driverFile = "drivers/drivers.csv"; // Assuming this file exists String raceFile = "racePerformance/race.csv"; // This file doesn't exist catchException(reportProcessor).generateReport(driverFile, raceFile); assertTrue(caughtException() instanceof FileNotFoundException); assertEquals("racePerformance/race.csv (No such file or directory)", caughtException().getMessage()); } @Test public void generateReportWithValidFiles() throws Exception { String driverFile = createTempDriverFile(); String raceFile = createTempRaceFile(); // Call the method and verify it runs without exceptions reportProcessor.generateReport(driverFile, raceFile); // Optionally verify the output } private String createTempDriverFile() { // Create and return the path of a temporary CSV file with driver data return "tempDriverFilePath"; // Replace with actual implementation } private String createTempRaceFile() { // Create and return the path of a temporary CSV file with race performance data return "tempRaceFilePath"; // Replace with actual implementation } } CatchException Library: If you're using the CatchException library, make sure it's compatible with JUnit 5. If you run into issues with it, consider using JUnit 5's Assertions.assertThrows() for exception testing.
@HimanshuKumar-ow7hw3 ай бұрын
CHATGPT: Converted JUnit 5 Test Class: import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertThrows; public class CalculatorTest { @Test public void squaredIntegerHappyPath() { Calculator calculator = new Calculator(); assertEquals(9, calculator.squareInteger(3)); assertEquals(100, calculator.squareInteger(10)); } @Test public void squaredIntegerUpperBoundary() { Calculator calculator = new Calculator(); // Using assertThrows to check for IllegalArgumentException assertThrows(IllegalArgumentException.class, () -> calculator.squareInteger(50000)); } @Test public void squaredIntegerLowerBoundary() { Calculator calculator = new Calculator(); // Using assertThrows to check for IllegalArgumentException assertThrows(IllegalArgumentException.class, () -> calculator.squareInteger(-50000)); } @Test public void squaredIntegerNull() { Calculator calculator = new Calculator(); assertEquals(0, calculator.squareInteger(null)); } @Test public void squaredIntegerNegative() { Calculator calculator = new Calculator(); assertEquals(25, calculator.squareInteger(-5)); } @Test public void squaredIntegerNaN() { Calculator calculator = new Calculator(); // Using assertThrows to check for IllegalArgumentException assertThrows(IllegalArgumentException.class, () -> calculator.squareInteger((int) Math.sqrt(-5))); } }
@HimanshuKumar-ow7hw3 ай бұрын
ChatGPT: JUnit 4 In JUnit 4, you can test for exceptions in two primary ways: Using @Test(expected = Exception.class): You can specify the expected exception using the expected attribute of the @Test annotation. java Copy code import org.junit.Test; public class MyTest { @Test(expected = IllegalArgumentException.class) public void testExceptionThrown() { // Code that should throw an exception int result = Integer.parseInt("invalid number"); } } In this example, if the code throws an IllegalArgumentException, the test will pass. Using try-catch with fail(): If you need more control over where the exception should be thrown (e.g., to verify the message), you can use a try-catch block along with fail(). java Copy code import org.junit.Test; import static org.junit.Assert.fail; public class MyTest { @Test public void testExceptionMessage() { try { int result = Integer.parseInt("invalid number"); fail("Exception not thrown!"); // Test will fail if this line is reached } catch (IllegalArgumentException e) { // Assert exception message assertEquals("For input string: \"invalid number\"", e.getMessage()); } } } JUnit 5 In JUnit 5, the approach is cleaner with the use of Assertions.assertThrows(). Using assertThrows(): This method allows you to specify the type of exception and the code that should throw it. java Copy code import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.assertThrows; public class MyTest { @Test public void testExceptionThrown() { // Expect an IllegalArgumentException assertThrows(IllegalArgumentException.class, () -> { Integer.parseInt("invalid number"); }); } } Checking the Exception Message: You can capture the thrown exception and assert specific details, like the message. java Copy code import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.*; public class MyTest { @Test public void testExceptionMessage() { IllegalArgumentException exception = assertThrows(IllegalArgumentException.class, () -> { Integer.parseInt("invalid number"); }); // Assert that the exception message matches the expected message assertEquals("For input string: \"invalid number\"", exception.getMessage()); } } Key Differences: In JUnit 4, you can use @Test(expected = Exception.class) but it doesn't allow you to verify exception messages or fine-tune where the exception is thrown. In JUnit 5, assertThrows() is a more flexible and modern approach, allowing you to check not only the type of the exception but also its message or any other behavior.
@yashwanthyerra28203 ай бұрын
does that mean doReturn() simplifies our work of mocking database/any such calls(i.e. we don't need to mock them as it is not interacting with that method) it simply provide us the response that we need to test the unit we need but not the dependencies
@skccharan3 ай бұрын
Thanks
@fredericocostaguedespereir92403 ай бұрын
Thank you so much, Aneesh!
@AneeshMistry3 ай бұрын
Glad it could help!
@ceriwestcott87843 ай бұрын
Why use a class for DiaryEntry instead of interface?
@GopalRoy-nn6ft3 ай бұрын
Autoscaling is not on ui in eks. Charges for contraol plane. Need to configure the autoscaling manually Nd metrics pods for autoscaling not default like othwr cloud kubernetes providers
@priyamghosh393 ай бұрын
Hi, Thanks for you video. We are using below two annotations and @RepeatedTest is not compatible with them, any clue what other options we have to run a junit test multiple times? @MethodSource @ParameterizedTest()
@AneeshMistry3 ай бұрын
Hi, I would take a look at using RunWith Parameterized.class
@White_King4 ай бұрын
exactly what I was looking for, thank you!
@AneeshMistry3 ай бұрын
Thank you!
@lakshmirengaswamy94674 ай бұрын
Thank you sir...
@pirateg3cko4 ай бұрын
Great stuff, dude!
@cher-54844 ай бұрын
That was clear, concise and very helpful. Thank you!
@djazzz_7114 ай бұрын
incredibly easy video gg
@christhianlor4 ай бұрын
Hi, Aneesh! How Are You? Very nice explanation!
@chaitanyakulkarni-tm2jj5 ай бұрын
Fantastic precious paid like content brother. May you get loads of subscribers and views.
thank you , good and clear explaination on junit mockito
@AneeshMistry5 ай бұрын
Glad it could help
@אסףלוטם-ק5צ5 ай бұрын
great video!
@AneeshMistry5 ай бұрын
Thank you
@robincannon25695 ай бұрын
I've been using angular for about the last 2 years. Mongodb has only just peaked my interest, but just got to say what a concise and straightforward angular tutorial you've presented. You clearly understand this framework very well. And thank you for the bhash suggestion i have to might replace my exisiting hashing method with that at some point. Good job :) thank you
@AneeshMistry5 ай бұрын
Thank you for your comment! I’m glad it could help you
@Vinayakgohel6 ай бұрын
Will it execute method which is mocked?
@AneeshMistry6 ай бұрын
A mock won’t have the method executed. If you want the real method executed you can use a spy, which then allows you to mock other methods, or a real instance
@jonathanlevy87056 ай бұрын
Thanks a ton, short and to the point.
@AneeshMistry6 ай бұрын
Thank you!
@ameyaghadigaonkar66306 ай бұрын
Great content bro
@AneeshMistry6 ай бұрын
Thank you!
@HarshFactsAboutGirls6 ай бұрын
fake accent of english makes video shit
@alighafari10116 ай бұрын
great thanks
@AneeshMistry6 ай бұрын
Thanks!
@jagadeeshp11637 ай бұрын
YOUR ARE MY SAVIOUR BROTHER LOVE THIS PLAYLIST
@AneeshMistry6 ай бұрын
Thank you so much!!
@CullenKuch7 ай бұрын
I am learning Angular and building a practice project. This series was exactly what I needed. Thank you so much! I got mine to work but now I just need to wrap my head around how its all actually working 😆
@AneeshMistry7 ай бұрын
Thank you! Try re-build the project component by component to build familiarity with Angular