This extends Mockit interview Q&As & examples on matching anyX field and withX() methods. JMockit offers a set of utility fields & methods for making argument matching more generic. 1) anyX fields like anyInt, … Read more ›...
This extends Mockit interview Q&As & examples on matching anyX field and withX() methods. JMockit offers a set of utility fields & methods for making argument matching more generic. 1) anyX fields like anyInt, … Read more ›...
JMockit offers a set of utility fields & methods for making argument matching more generic. 1) anyX fields like anyInt, anyBoolean, anyString, etc. There is one for each primitive type, and the corresponding wrapper class, … Read more ›...
This extends JMockit interview Q&As & examples on Partial Mocking with MockUp. What is Deencapsulation utility class used for? Mocking and testing of private methods or inner classes is often not considered good practice. Earlier we had looked at the Faking API with MockUp<T> to mock private methods. … Read...
There are times you want to Mock the superclass & test only the subclass. Superclass that should not be invoked The BaseService.java:
|
1 2 3 4 5 6 7 8 9 |
package com.myapp; public class BaseService { public BaseService(){ throw new IllegalArgumentException("Should not reach here"); } } |
Subclass to be tested The MyService.java:
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
package com.myapp; public class MyService extends BaseService { private int num1; private int num2; public MyService(int num1, int num2) { super(); this.num1 = num1; this.num2 = num2; } public int eval() { return num1 + num2; } } |
JUnit test class The BaseService.java will be mocked as shown below. … Read more ›...
We often write code that depends on Singletons. Writing unit tests in this case could be tricky. Here is an example demonstrating how to solve the problem with JMockit. Is Singleton pattern an anti-pattern? The Singleton pattern is a design pattern that restricts the instantiation of a class to one...
This Java code review checklist is not only useful during code reviews, but also to answer an important Java job interview question, Q. How would you go about evaluating code quality of others’ work? This can judge a candidate’s real experience & … Read more ›...
Q1 Why use mock objects in unit testing? A1 Unit testing is widely accepted as a “best practice” for software development. When you write an object, you must also provide an automated test class containing methods by calling its various public methods with various parameters and making sure that the...
Performance testing is an important process of any software development. You can bring this up yourself to many open-ended questions like — Tell me about yourself? What are some of your recent accomplishments that you are proud of? Setting up a performance/load test script is always the first step in...
This is an integration testing that tests Spring transaction through service, and DAO layers all the way up to the embedded database like HSQLDB or H2. After commit or rollback, the number of records in the table are verified. The service layer defines the transactional boundaries with the “@Transactional” annotation....
This tutorial extends SonarQube with Maven Tutorial – Code Quality for Java developers to use Jacoco for tracking unit test coverage. Jacoco is the default code coverage tool that gets shipped with SonarQube. SonarQube can also be configured to use Cobertura as the code coverage tool.
…
Q1. What is BDD? A1. BDD is principally an idea about how software development should be managed by both business interests and technical insight. Test-driven development focuses on the developer’s opinion on how parts of the software should work. Behavior-driven development focuses on the users’ opinion on how they want...
To appreciate jBehave, let’s look at a better example here. This example is about a science formula Speed = distance / Time. So, given distance and time, calculate speed given speed and time, calculate distance given speed and distance, … Read more ›...
This extends the jBehave — Behavioural Driven Development (BDD) Q&A to use the same example with jUnit testing. Step 1: Make sure that you have both jUnit and jBehave in your pom.xml file.
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
<dependency> <groupId>org.jbehave</groupId> <artifactId>jbehave-core</artifactId> <version>3.8</version> </dependency> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.10</version> <scope>test</scope> </dependency> |
Step 2: Refer to Behavioural Driven Development (BDD) for all the jBehave implementation. … Read more ›...
I have a good news, I got job offer. I like to share with you from my bottom of my heart feeling thankful to you.