QA Interview Hub · Knowledge base · Quizzes · Українська
All topics
Java Core interview questions
41 questions on Java Core, from the basics to the hard ones. Answers and explanations are in the quiz and the knowledge base.
By level: Junior QA interview questions · Middle QA interview questions · Senior QA interview questions
The language for tests
- What does this code print? Junior
String a = "qa";
String b = new String("qa");
System.out.println(a == b);
System.out.println(a.equals(b));
- A test builds a large report string in a loop of many thousands of iterations. What is more appropriate? Junior
- What is the advantage of enum Environment { DEV, STAGING, PROD } over the string "staging" in test configuration? Junior
- What does this code print? Middle
Integer a = 127, b = 127;
Integer c = 1000, d = 1000;
System.out.println((a == b) + " " + (c == d));
- What does the compiler automatically add to record Credentials(String email, String password)? Middle
Take the quiz for this chapter · Read the explanation in the knowledge base
OOP in a framework
- What is appropriate to move into a BaseTest base class? Junior
- Why are locators in a page class usually private and actions public? Junior
- What does final mean in the line final List<String> names = new ArrayList<>();? Middle
- A header with a menu repeats on twenty pages. What is the best way to model it? Middle
- Tests run in four threads. What goes wrong with this base class? Middle
public class BaseTest {
protected static WebDriver driver;
@BeforeEach
void setUp() {
driver = new ChromeDriver();
}
@AfterEach
void tearDown() {
driver.quit();
}
}
- Tests must work with both a local browser and a cloud Grid. What is a convenient way to design this in a framework? Middle
Take the quiz for this chapter · Read the explanation in the knowledge base
Collections and test data
- What happens when this code runs? Junior
List<String> browsers = List.of("chrome", "firefox");
browsers.add("edge");
- A test needs to quickly get a ready test user by the role "admin" or "guest". Which structure fits? Junior
- What does this code print and why? Middle
class User {
String email;
User(String email) { this.email = email; }
@Override public boolean equals(Object o) {
return o instanceof User u && u.email.equals(email);
}
}
Set<User> set = new HashSet<>();
set.add(new User("a@x.com"));
System.out.println(set.contains(new User("a@x.com")));
- After an API update the response got a new field and Jackson deserialisation into a POJO failed with UnrecognizedPropertyException. What should be done? Middle
- What is the more reliable way to read users.json located in src/test/resources? Middle
Take the quiz for this chapter · Read the explanation in the knowledge base
Exceptions
- Which of these exceptions is checked, meaning the compiler forces you to handle or declare it? Junior
- Why is this block dangerous in a test? Junior
try {
client.deleteUser(id);
} catch (Exception e) {
// ignore
}
- What happens if price equals 90? Middle
try {
assertThat(price).isEqualTo(100);
} catch (Exception e) {
log.warn("ignored", e);
}
- What does try-with-resources guarantee in try (var in = Files.newInputStream(path)) { ... }? Middle
- How do you correctly wrap an IOException in a custom exception of the test code? Middle
Take the quiz for this chapter · Read the explanation in the knowledge base
Lambdas and the Stream API
- Which functional interface does the filter method of a Stream expect? Junior
- What will titles contain? Junior
List<String> titles = rows.stream()
.map(WebElement::getText)
.filter(t -> !t.isBlank())
.toList();
- Will the logging in peek run? Middle
orders.stream()
.peek(o -> log.info("order {}", o.id()))
.filter(o -> o.total() > 100);
- Why can orElse(createUser()) be a problem in such a call? Middle
User user = users.stream()
.filter(u -> u.role() == Role.ADMIN)
.findFirst()
.orElse(createUser(Role.ADMIN));
- Why does this code not compile? Middle
int count = 0;
items.forEach(i -> count++);
Take the quiz for this chapter · Read the explanation in the knowledge base
Parallelism
- What is a race condition in parallel tests? Junior
- What does ThreadLocal<WebDriver> give in parallel tests? Middle
- Why call remove() on a ThreadLocal after a test if tests run on a thread pool? Middle
- Why can the total be lower than the real number of passed tests? Middle
static int passed = 0;
// executed by tests running in 4 threads
passed++;
- A test manually created an ExecutorService for parallel requests. What must be done at the end? Middle
Take the quiz for this chapter · Read the explanation in the knowledge base
Assertions and API tests
- Which form of assertion is correct in AssertJ? Junior
- Below is the whole test body, with no JUnit extensions. What is wrong with this use of AssertJ soft assertions? Middle
SoftAssertions softly = new SoftAssertions();
softly.assertThat(user.name()).isEqualTo("Anna");
softly.assertThat(user.role()).isEqualTo("admin");
- In a REST Assured given() ... when() ... then() chain, where are the method and path of the request set? Junior
- What does extract().as(User.class) do at the end of a REST Assured chain? Middle
- What makes a Builder useful for test data (custom or Lombok @Builder)? Middle
Take the quiz for this chapter · Read the explanation in the knowledge base
The test project
- What does <scope>test</scope> mean for a dependency in pom.xml? Junior
- Which command runs only the single test class LoginTest? Junior
- Which Maven plugin is meant for integration tests and why does a separate goal check its result? Middle
- What does the command mvn test -Dgroups=smoke do? Middle
- Why is the second SLF4J logger call better than the first? Middle
log.info("Order " + orderId + " created");
log.info("Order {} created", orderId);
Take the quiz for this chapter · Read the explanation in the knowledge base