-
Notifications
You must be signed in to change notification settings - Fork 612
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
2026: deprecate robotInit #6845
Comments
Will |
|
Since you can't override constructors in anonymous subclasses, loss of var testRobot1 = new MyTimedRobot() {
public void simulationInit() {
// test-specific robot initialization code
}
};
assertRobotWorks(testRobot1); which is convenient for testing. To workaround the loss of |
You can't override constructors, but you can make an initialization block which fulfills basically the same purpose |
Fair enough, but an initialization block still isn't quite the same as |
simulationInit() being called in startCompetition() instead of the robot constructor doesn't actually matter. robotInit() is called first in startCompetition(), simulationInit() is called right after that (see here), and startCompetition() is called right after the robot constructor. See #6623 (comment) for more information. |
|
An initializer block as suggested in #6845 (comment) should meet that need. From https://docs.oracle.com/javase/tutorial/java/javaOO/initial.html:
Just make a new object for every test with a different initialization block. |
While I agree that would often be sufficient, my point was just that an initialization block is not technically equivalent to Just for clarity, as an example of where an initialization block would not be equivalent to MyTimedRobot testRobot;
boolean testRequiresSpecialSim;
@BeforeEach
void setup() {
testRobot = new MyTimedRobot() {
public void simulationInit() {
if (testRequiresSpecialSim) {
initSpecialSim();
}
}
};
}
@Test
void normalTest() {
assertRobotWorks();
}
@Test
void specialTest1() {
testRequiresSpecialSim = true;
// ... other test-specific test setup
assertRobotWorks();
}
@Test
void specialTest2() {
testRequiresSpecialSim = true;
// ... other test-specific test setup
assertRobotWorks();
}
void assertRobotWorks() {
testRobot.startCompetition();
assertGotExpectedResult1();
// ...
assertGotExpectedResultN();
} But again, I'm ok with the removal of void setup() {
testRobot = new MyTimedRobot() {
public void startCompetition() {
if (testRequiresSpecialSim) {
initSpecialSim();
}
super.startCompetition();
}
};
} |
I'm actually not sure what test-specific stuff you'd even put in a test-only anonymous class. The simulation stuff like sim counterparts of real objects should already be in the robot class or subsystems. I also can't think of a case off the top of my head where you'd make the simulation init different. When 3512 unit and integration tested their entire robot in 2020, the tests used the same setters (e.g., pose reset) and getters (e.g., sensor values) the real code did. The only exception was calls to DriverStationSim in the test body itself, because the test was injecting stimuli. |
As a specific example, perhaps for the "special" tests we want to use an external virtual world simulator instead of the sims created in the robot class. In that case, To be clear, I agree that there are other ways to achieve this. I'm just providing an example of a way that someone might want to organize their code when using |
Duplicate of #6622. |
No description provided.
The text was updated successfully, but these errors were encountered: