这是我的代码,我无法编写Junit测试用例。我是第一次编写测试用例,这是我第一次使用Javafx编写测试用例,而且我也不怎么开始用Javafx编写测试用例。我正在使用javafx8,并且正在使用此jar文件。
junit 4.12
hamcrest 1.3
mockito-all-1.9.5
testfx-core-4.0.14-alpha
TestNG 6.8.1-testing-6.8.1-dist.jar
public class SampleController implements Initializable {
@FXML
private Label label;
@FXML
private Button applyButton;
@FXML
private TextField firstName;
@FXML
private TextField lastName;
/**
* Initializes the controller class.
*/
@Override
public void initialize(URL url, ResourceBundle rb) {
// TODO
applyButton.disableProperty().bind(
firstName.textProperty().isEmpty()
.or(
lastName.textProperty().isEmpty()
));
}
@FXML
private void applyButtonClicked(ActionEvent event) {
label.setText(firstName.getText());
}
}
// this my respective test class
public class SampleControllerNGTest {
public SampleControllerNGTest() {
}
@BeforeClass
public static void setUpClass() throws Exception {
}
@AfterClass
public static void tearDownClass() throws Exception {
}
@BeforeMethod
public void setUpMethod() throws Exception {
}
@AfterMethod
public void tearDownMethod() throws Exception {
}
/**
* Test of initialize method, of class SampleController.
*/
@Test
public void testInitialize() {
System.out.println("initialize");
URL url = null;
ResourceBundle rb = null;
SampleController instance = new SampleController();
instance.initialize(url, rb);
// TODO review the generated test code and remove the default call to fail.
fail("The test case is a prototype.");
}
}