BlueJ Trick - Save your Object Bench using Test Fixtures
Material in Courses: Info1 Tags: BluejYou can save and re-create your Object Bench with a trick that uses the Unit Test Support in BlueJ, especially “Object Bench to Test Fixture” “Test Fixture to Object Bench”:
1. Save the state of your object bench
Let’s say you have created a lot of objects manually and want to reuse them. To save the state of your Object Bench, first create a Test Class for an arbitrary class:
Now, call “Object Bench to Test Fixture” from the Test Class’ context menu.
This will save all variables for the created objects as Field declarations, and all method calls in the method annotated with @BeforeEach in the TestClass (StudentTestClass in this example):
You can then edit and expand this method - e.g. change student1&2 to better variable names, or even add more objects simply with copy&paste. Remember to adjust the field (variable) declarations at the top of the class!
2. Re-create the Objects
You can then re-create the objects using “TestFixture to Object Bench” form the Test Class Menu:
Voila! Here’s your object bench again with the new variable names:
3. … and repeat:
You can even call methods on your re-created Work Bench and store them again using “Object Bench to Test Fixture”. As there is already a @BeforeEach method, you need to confirm to replace it: