我注意到从Control类继承的每个元素底部都有一个下划线.你可以在图片中看到它:
当我把焦点放在任何一个项目上时,该线条就消失了.为什么会这样,我怎么能摆脱它?
码:
Main.java
package sample;
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.stage.Stage;
public class Main extends Application {
@Override
public void start(Stage primaryStage) throws Exception{
Parent root = FXMLLoader.load(getClass().getResource("sample.fxml"));
primaryStage.setTitle("Hello World");
primaryStage.setScene(new Scene(root, 300, 275));
primaryStage.show();
}
public static void main(String[] args) {
launch(args);
}
}
Run Code Online (Sandbox Code Playgroud)
sample.fxml
<?import javafx.scene.layout.GridPane?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.ProgressBar?>
<?import javafx.scene.layout.HBox?>
<?import javafx.scene.control.ComboBox?>
<?import java.lang.String?>
<?import javafx.collections.FXCollections?>
<GridPane stylesheets="@sample.css"
xmlns:fx="http://javafx.com/fxml"
alignment="center">
<HBox>
<ProgressBar minWidth="100" progress="0.3"/>
<Button text="Button"/>
<Button text="Button"/>
<Button text="Button"/>
<ComboBox> …Run Code Online (Sandbox Code Playgroud) 我创建了一个从JSSC库扩展的类,该类使用低级通信方法(sendByte,sendString等)。我想通过JUnit对其进行测试,但我不太了解该怎么做。
例如,让我们看一下下面的方法:
public void openConnection() throws SerialPortException {
serialPort.openPort();
configureConnectionParameters(serialPort);
configureReadListener(serialPort);
}
Run Code Online (Sandbox Code Playgroud)
为了确保该方法正常工作,我需要一个实际的硬件设备来查看端口是否正确打开,并且在配置过程中没有引发任何异常。但是通常在单元测试期间使用外部资源被认为是一种不好的做法,因此我开始怀疑是否有解决此类问题的解决方案(可能是模拟硬件?)。
或者,我是否必须对它进行单元测试?
让我们考虑一个示例代码:
SimpleIntegerProperty simpleIntegerProperty = new SimpleIntegerProperty(0);
simpleIntegerProperty.addListener((observable, oldValue, newValue) -> {
// execution code when the event is fired.
});
Run Code Online (Sandbox Code Playgroud)
当我使用方法设置新值时setValue(),如果 oldValue 和 newValue 相同,则不会触发该事件。仅当它们不同时。
一个例子:
ListView<Element>的绑定ObservableList<Element>。Procedure是一个不同的班级。它对元素做了一些事情,并且还包含SimpleIntegerPorperty-currentlyChosenElementIndex来指示当前所选元素的索引。当当前元素正在进行时,我希望ListView显示这一点。现在,在该过程中,GUI 被阻止,并且ListView在继续进行时在 上选择当前元素。程序结束后,应用程序重置currentlyChosenElementIndex为零,这是我遇到问题的索引。当该过程启动时,不会选择第一个元素,因为该应用程序setValue()与先前的元素相同。
有什么办法可以改变这种情况吗?
假设我有一个类MyClass.java,我们必须为它编写一个测试。其中一些将执行一次,其中一些将执行多次。
MyClassTestSingle.java用于单个测试和MyClassTestMultiple.java带@Parametrized注释的测试。 MyClassTestSuite.java.MyClassTestSingle.java和MyClassTestMultiple.java方法中,我使用具有相同值的相同参数,所以我开始考虑包含这些参数的类......但后来我意识到我想创建四个类来测试一个类。所以我开始寻找一些“好的实践”如何保持我的测试类干净和简单。但是在为上述情况编写测试时,没有发现有关我需要的类数量的有价值的信息。
我开始想,也许我的MyClass.java.
我错了吗?或者,也许我只是不明白什么?