Open thchanao opened 6 years ago
Good question. You cannot test with those UI related function easily - this is the problem.
1) You can face the problem by learning more. Like understand why the UI testing fail (why there is null pointer exception), and solve the problem by using the same framework or an extra framework.
2) You can avoid the problem by reviewing your code structure: Your code probably looks like
void functionA() {
//get UI value
//logic
//set UI value
}
You should take out the logic part to another function as
void function() {
//get UI value
String result = logic(UIvalue);
//set UI value
}
public String logic(String UIvalue) {
//logic
return String_to_update_in_UI;
}
Your logic function is then testable.
3) If you do the above, the updated functionA can be applied for "Exclusion" when we calcuate the branch coverage because it only involve UI operation. Don't exploit this exclusion rule as a loophole and try to put many many codes inside your functionA. We may not approve your exclusion if you do that intentionally.
What about mouse click events? Can we exclude the logic inside the mouse click events during testing?
We handle that in similar manner. So, logic cannot be excluded. You can only extract the event and redirect your request to another testable function.
For mouse click event, may I use java.awt.robot to simulate a mouse click? I am not sure if this violates the rule 3 of technical requirement. Thanks.
Or could I change the version of JavaFX used to JavaFX 11 to make use of javafx.scene.robot for the abovementioned use?
For WebScraper class, I can use constructor to construct an object and test the scrape function. But I cannot do it with Controller class. How can I test the function inside Controller class.