-
Notifications
You must be signed in to change notification settings - Fork 121
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
SWTBot test case: Partition Table Editor #1012
base: master
Are you sure you want to change the base?
Conversation
WalkthroughThe changes introduce multiple new test methods to the Changes
PoemIn the land of code where rabbits play, Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 2
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files selected for processing (1)
- tests/com.espressif.idf.ui.test/src/com/espressif/idf/ui/test/executable/cases/project/NewEspressifIDFProjectPartitionTableEditorTest.java (1 hunks)
Additional comments not posted (6)
tests/com.espressif.idf.ui.test/src/com/espressif/idf/ui/test/executable/cases/project/NewEspressifIDFProjectPartitionTableEditorTest.java (6)
35-38
: Specify a more specific exception type.The
beforeTestClass
method currently throws a genericException
. It's better to specify a more specific exception type to improve readability and error handling.- public static void beforeTestClass() throws Exception + public static void beforeTestClass() throws IOException
55-60
: Make the sleep duration configurable or add a comment.The
loadEnv
method includes a sleep duration of 1000 milliseconds. Consider making this duration configurable or adding a comment to explain its necessity.- bot.sleep(1000); + bot.sleep(1000); // Sleep to ensure the environment is fully set upOR
private static final int SLEEP_DURATION = 1000; private static void loadEnv() throws Exception { bot = WorkBenchSWTBot.getBot(); EnvSetupOperations.setupEspressifEnv(bot); bot.sleep(SLEEP_DURATION); }
62-66
: LGTM!The method
givenNewEspressifIDFProjectIsSelected
is correctly implemented.
68-71
: LGTM!The method
givenProjectNameIs
is correctly implemented.
73-76
: LGTM!The method
whenNewProjectIsSelected
is correctly implemented.
78-83
: LGTM!The method
whenProjectIsBuiltUsingContextMenu
is correctly implemented.
public void afterEachTest() | ||
{ | ||
Fixture.cleanTestEnv(); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Handle potential exceptions within the method.
The afterEachTest
method currently does not handle potential exceptions. Consider adding exception handling to ensure the test environment is cleaned up properly even if an error occurs.
@After
public void afterEachTest() {
try {
Fixture.cleanTestEnv();
} catch (Exception e) {
// Log the exception and proceed with cleanup
e.printStackTrace();
}
}
private static void cleanTestEnv() | ||
{ | ||
TestWidgetWaitUtility.waitForOperationsInProgressToFinishAsync(bot); | ||
ProjectTestOperations.closeAllProjects(bot); | ||
ProjectTestOperations.deleteAllProjects(bot); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Handle potential exceptions within the method.
The cleanTestEnv
method currently does not handle potential exceptions. Consider adding exception handling to ensure the test environment is cleaned up properly even if an error occurs.
private static void cleanTestEnv() {
try {
TestWidgetWaitUtility.waitForOperationsInProgressToFinishAsync(bot);
ProjectTestOperations.closeAllProjects(bot);
ProjectTestOperations.deleteAllProjects(bot);
} catch (Exception e) {
// Log the exception and proceed with cleanup
e.printStackTrace();
}
}
@alirana01 please review this |
f64ad58
to
2acabf6
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
Outside diff range and nitpick comments (1)
tests/com.espressif.idf.ui.test/src/com/espressif/idf/ui/test/executable/cases/project/NewEspressifIDFProjectPartitionTableEditorTest.java (1)
47-55
: Refactor the method name to follow Java naming conventions.The method name is very long and does not follow the Java naming conventions. Please refactor it to a shorter name that follows the camelCase convention.
For example:
@Test public void testPartitionTableEditorDisabledForNewUnbuiltProject() throws Exception { // ... }
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files selected for processing (3)
- tests/com.espressif.idf.ui.test/src/com/espressif/idf/ui/test/executable/cases/project/NewEspressifIDFProjectPartitionTableEditorTest.java (1 hunks)
- tests/com.espressif.idf.ui.test/src/com/espressif/idf/ui/test/executable/cases/project/NewEspressifIDFProjectTest.java (1 hunks)
- tests/com.espressif.idf.ui.test/src/com/espressif/idf/ui/test/operations/ProjectTestOperations.java (0 hunks)
Files not reviewed due to no reviewable changes (1)
- tests/com.espressif.idf.ui.test/src/com/espressif/idf/ui/test/operations/ProjectTestOperations.java
Additional comments not posted (10)
tests/com.espressif.idf.ui.test/src/com/espressif/idf/ui/test/executable/cases/project/NewEspressifIDFProjectPartitionTableEditorTest.java (9)
35-39
: LGTM!The
beforeTestClass
method is correctly implemented to load the test environment.
41-45
: Skipping comment as the past review feedback is still applicable.Please address the exception handling suggestion from the previous review round.
64-69
: LGTM!The
loadEnv
method is correctly implemented to load the test environment.
71-75
: LGTM!The
givenNewEspressifIDFProjectIsSelected
method is correctly implemented to set up the project category and subcategory for the test.
77-80
: LGTM!The
givenProjectNameIs
method is correctly implemented to set up the project name for the test.
82-85
: LGTM!The
whenNewProjectIsSelected
method is correctly implemented to set up a new project for the test.
94-97
: LGTM!The
whenOpenPartitionTableEditor
method is correctly implemented to open the partition table editor for the test.
99-104
: LGTM!The
thenEditorIsDisabled
method is correctly implemented to validate the partition table editor is disabled for the test.
106-111
: Skipping comment as the past review feedback is still applicable.Please address the exception handling suggestion from the previous review round.
tests/com.espressif.idf.ui.test/src/com/espressif/idf/ui/test/executable/cases/project/NewEspressifIDFProjectTest.java (1)
273-273
: LGTM!The change refactors the method call to use a more generic
launchCommandUsingContextMenu
method, which improves code reusability and maintainability. The behavior of the test case remains unchanged.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files selected for processing (2)
- tests/com.espressif.idf.ui.test/src/com/espressif/idf/ui/test/executable/cases/project/NewEspressifIDFProjectPartitionTableEditorTest.java (1 hunks)
- tests/com.espressif.idf.ui.test/src/com/espressif/idf/ui/test/operations/ProjectTestOperations.java (3 hunks)
Files skipped from review as they are similar to previous changes (1)
- tests/com.espressif.idf.ui.test/src/com/espressif/idf/ui/test/executable/cases/project/NewEspressifIDFProjectPartitionTableEditorTest.java
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
Outside diff range and nitpick comments (2)
tests/com.espressif.idf.ui.test/src/com/espressif/idf/ui/test/operations/ProjectTestOperations.java (2)
581-588
: LGTM! Consider adding error handling.The
checkShellContent
method is well-structured and serves a clear purpose. The naming of the method and variables is appropriate and self-explanatory.As an improvement, consider adding error handling for exceptional cases, such as when the specified shell or label is not found. This will make the method more robust and provide better feedback to the caller.
590-616
: LGTM! Consider adding error handling.The
checkPartitionTableContent
method is well-structured and serves a clear purpose. The naming of the method and variables is appropriate and self-explanatory.As an improvement, consider adding error handling for exceptional cases, such as when the table is not found or has a different structure. This will make the method more robust and provide better feedback to the caller.
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files selected for processing (2)
- tests/com.espressif.idf.ui.test/src/com/espressif/idf/ui/test/executable/cases/project/NewEspressifIDFProjectPartitionTableEditorTest.java (1 hunks)
- tests/com.espressif.idf.ui.test/src/com/espressif/idf/ui/test/operations/ProjectTestOperations.java (3 hunks)
Files skipped from review as they are similar to previous changes (1)
- tests/com.espressif.idf.ui.test/src/com/espressif/idf/ui/test/executable/cases/project/NewEspressifIDFProjectPartitionTableEditorTest.java
Additional comments not posted (1)
tests/com.espressif.idf.ui.test/src/com/espressif/idf/ui/test/operations/ProjectTestOperations.java (1)
Line range hint
629-647
: LGTM!The
joinJobByName
method is well-structured and serves a clear purpose. The naming of the method and variables is appropriate and self-explanatory.The method handles the
InterruptedException
by logging an error message, which is a good practice.No changes are necessary.
public static boolean compareRows(SWTWorkbenchBot bot) throws IOException | ||
{ | ||
SWTBotTable table = bot.table(); | ||
int defaultRows = 3; | ||
int actualRows = table.rowCount(); | ||
if (1 != (actualRows - defaultRows)) | ||
{ | ||
return false; | ||
} | ||
return true; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fix the incorrect logic.
The logic of the compareRows
method seems incorrect. It checks if the actual number of rows is not equal to the default value plus one, which is the opposite of what the method name suggests.
If the actual number of rows is equal to the default value plus one, the method should return true
, but it returns false
instead.
Please update the logic to match the expected behavior:
public static boolean compareRows(SWTWorkbenchBot bot) throws IOException
{
SWTBotTable table = bot.table();
int defaultRows = 3;
int actualRows = table.rowCount();
return actualRows == defaultRows + 1;
}
This will ensure that the method returns true
when the actual number of rows is equal to the default value plus one, and false
otherwise.
please, review @alirana01 @sigmaaa Tests cover basic functional checks:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@AndriiFilippov LGTM can you please verify the builds they are failing on linux
edit:Seems like failures are not your tests
So, could merge ? |
4e33063
to
d48e8b0
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 6
🧹 Outside diff range and nitpick comments (1)
tests/com.espressif.idf.ui.test/src/com/espressif/idf/ui/test/executable/cases/project/NewEspressifIDFProjectPartitionTableEditorTest.java (1)
156-161
: Consider combining build operations into a single utility methodThe method
whenProjectIsBuiltUsingContextMenu
performs multiple steps to build the project. To improve code reusability and readability, consider combining these steps into a single utility method withinProjectTestOperations
.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
📒 Files selected for processing (3)
- tests/com.espressif.idf.ui.test/src/com/espressif/idf/ui/test/executable/cases/project/NewEspressifIDFProjectPartitionTableEditorTest.java (1 hunks)
- tests/com.espressif.idf.ui.test/src/com/espressif/idf/ui/test/executable/cases/project/NewEspressifIDFProjectTest.java (1 hunks)
- tests/com.espressif.idf.ui.test/src/com/espressif/idf/ui/test/operations/ProjectTestOperations.java (2 hunks)
🔇 Additional comments (7)
tests/com.espressif.idf.ui.test/src/com/espressif/idf/ui/test/executable/cases/project/NewEspressifIDFProjectTest.java (2)
Line range hint
273-279
: Improved code reusability with generic command launch methodThe change to use
ProjectTestOperations.launchCommandUsingContextMenu
is a good improvement. It enhances code reusability and flexibility by using a generic method to launch context menu commands. This approach can be easily extended to other commands in the future.
Line range hint
282-284
: Consistent use of generic command launch method for project refreshThis change aligns well with the previous modification, using
ProjectTestOperations.launchCommandUsingContextMenu
for the refresh operation. It maintains consistency in how context menu commands are executed across different operations, which is a good practice for code maintainability.tests/com.espressif.idf.ui.test/src/com/espressif/idf/ui/test/executable/cases/project/NewEspressifIDFProjectPartitionTableEditorTest.java (3)
221-226
: Exception handling incleanTestEnv
methodAs previously mentioned in past review comments, the
cleanTestEnv
method does not handle potential exceptions. Incorporating exception handling ensures that cleanup processes are executed properly even if errors occur.
42-46
: Exception handling inafterEachTest
methodAs previously mentioned in past review comments, the
afterEachTest
method callsFixture.cleanTestEnv()
without exception handling. Ensure that exceptions are caught and managed to prevent tests from failing silently.
31-34
:⚠️ Potential issueAdjust method naming conventions in the
Fixture
inner classIn Java, method names should follow the camelCase convention starting with a lowercase letter. The methods within the
Fixture
class begin with uppercase letters (e.g.,ThenInformationMessagePopUp()
), which is inconsistent with Java naming conventions. Please rename these methods to improve code readability and maintainability.Apply this diff to rename the methods:
- private static void ThenInformationMessagePopUp() throws IOException + private static void thenInformationMessagePopUp() throws IOException - private static void ThenBuiltInPartitionTableDisplayed() throws IOException + private static void thenBuiltInPartitionTableDisplayed() throws IOException - private static void ThenCheckRowAdded() throws IOException + private static void thenCheckRowAdded() throws IOException - private static void ThenCheckRowDeleted() throws IOException + private static void thenCheckRowDeleted() throws IOException - private static void ThenCheckChangesSaved() throws IOException + private static void thenCheckChangesSaved() throws IOExceptionLikely invalid or redundant comment.
tests/com.espressif.idf.ui.test/src/com/espressif/idf/ui/test/operations/ProjectTestOperations.java (2)
27-30
: LGTM on the added importsThe new imports for
SWTBotLabel
andSWTBotTable
are appropriate for the added functionalities.
618-624
: LGTM oncomparePartitionTableRows
methodThe method
comparePartitionTableRows
correctly calculates the difference in row count and compares it to the expected difference.
@Test | ||
public void givenNewProjectCreatedNotBuiltWhenOpenPartitionTableEditorThenInformationPopUpMessage() throws Exception | ||
{ | ||
Fixture.givenNewEspressifIDFProjectIsSelected("EspressIf", "Espressif IDF Project"); | ||
Fixture.givenProjectNameIs("NewProjectPartitionTableEditor1Test"); | ||
Fixture.whenNewProjectIsSelected(); | ||
Fixture.whenOpenPartitionTableEditor(); | ||
Fixture.ThenInformationMessagePopUp(); | ||
} | ||
|
||
@Test | ||
public void givenNewProjectCreatedBuiltWhenOpenPartitionTableEditorThenBuiltInPartitionTableDisplayed() | ||
throws Exception | ||
{ | ||
Fixture.givenNewEspressifIDFProjectIsSelected("EspressIf", "Espressif IDF Project"); | ||
Fixture.givenProjectNameIs("NewProjectPartitionTableEditor2Test"); | ||
Fixture.whenNewProjectIsSelected(); | ||
Fixture.whenProjectIsBuiltUsingContextMenu(); | ||
Fixture.whenOpenPartitionTableEditor(); | ||
Fixture.ThenBuiltInPartitionTableDisplayed(); | ||
} | ||
|
||
@Test | ||
public void givenNewProjectCreatedBuiltWhenOpenPartitionTableEditorWhenAddRowThenCheckRowAdded() throws Exception | ||
{ | ||
Fixture.givenNewEspressifIDFProjectIsSelected("EspressIf", "Espressif IDF Project"); | ||
Fixture.givenProjectNameIs("NewProjectPartitionTableEditor3Test"); | ||
Fixture.whenNewProjectIsSelected(); | ||
Fixture.whenProjectIsBuiltUsingContextMenu(); | ||
Fixture.whenOpenPartitionTableEditor(); | ||
Fixture.whenAddRowToPartitionTable(); | ||
Fixture.ThenCheckRowAdded(); | ||
} | ||
|
||
@Test | ||
public void givenNewProjectCreatedBuiltWhenOpenPartitionTableEditorWhenDeleteSelectedRowThenCheckRowDeleted() | ||
throws Exception | ||
{ | ||
Fixture.givenNewEspressifIDFProjectIsSelected("EspressIf", "Espressif IDF Project"); | ||
Fixture.givenProjectNameIs("NewProjectPartitionTableEditor4Test"); | ||
Fixture.whenNewProjectIsSelected(); | ||
Fixture.whenProjectIsBuiltUsingContextMenu(); | ||
Fixture.whenOpenPartitionTableEditor(); | ||
Fixture.whenDeleteRowFromPartitionTable(); | ||
Fixture.ThenCheckRowDeleted(); | ||
} | ||
|
||
@Test | ||
public void givenNewProjectCreatedBuiltWhenOpenPartitionTableEditorWhenDeleteSelectedRowWhenSaveAndQuitwhenReopenPartitionTableThenCheckChangesSaved() | ||
throws Exception | ||
{ | ||
Fixture.givenNewEspressifIDFProjectIsSelected("EspressIf", "Espressif IDF Project"); | ||
Fixture.givenProjectNameIs("NewProjectPartitionTableEditor5Test"); | ||
Fixture.whenNewProjectIsSelected(); | ||
Fixture.whenProjectIsBuiltUsingContextMenu(); | ||
Fixture.whenOpenPartitionTableEditor(); | ||
Fixture.whenDeleteRowFromPartitionTable(); | ||
Fixture.whenSaveAndQuit(); | ||
Fixture.whenOpenPartitionTableEditor(); | ||
Fixture.thenCheckChangesSaved(); | ||
} | ||
|
||
@Test | ||
public void givenNewProjectCreatedBuiltWhenOpenPartitionTableEditorWhenDeleteSelectedRowWhenSaveAndCancelwhenReopenPartitionTableThenCheckChangesSaved() | ||
throws Exception | ||
{ | ||
Fixture.givenNewEspressifIDFProjectIsSelected("EspressIf", "Espressif IDF Project"); | ||
Fixture.givenProjectNameIs("NewProjectPartitionTableEditor6Test"); | ||
Fixture.whenNewProjectIsSelected(); | ||
Fixture.whenProjectIsBuiltUsingContextMenu(); | ||
Fixture.whenOpenPartitionTableEditor(); | ||
Fixture.whenDeleteRowFromPartitionTable(); | ||
Fixture.whenSavePartitionTable(); | ||
Fixture.whenCancel(); | ||
Fixture.whenOpenPartitionTableEditor(); | ||
Fixture.thenCheckChangesSaved(); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Place assertions directly within test methods for clarity
While using the Fixture
class helps to organize code, placing assertions directly within the test methods enhances test clarity and makes it easier to understand the test flow. Consider refactoring the tests to include assertions in the test methods.
private static void loadEnv() throws Exception | ||
{ | ||
bot = WorkBenchSWTBot.getBot(); | ||
EnvSetupOperations.setupEspressifEnv(bot); | ||
bot.sleep(1000); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Avoid using fixed delays like bot.sleep(1000);
Using fixed delays can lead to flaky tests due to variable execution times. Instead, use explicit wait conditions provided by SWTBot to wait for specific UI elements or operations to complete.
Apply this diff to replace bot.sleep(1000);
with a proper wait condition:
private static void loadEnv() throws Exception
{
bot = WorkBenchSWTBot.getBot();
EnvSetupOperations.setupEspressifEnv(bot);
- bot.sleep(1000);
+ TestWidgetWaitUtility.waitForOperationsInProgressToFinishAsync(bot);
}
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
private static void loadEnv() throws Exception | |
{ | |
bot = WorkBenchSWTBot.getBot(); | |
EnvSetupOperations.setupEspressifEnv(bot); | |
bot.sleep(1000); | |
} | |
private static void loadEnv() throws Exception | |
{ | |
bot = WorkBenchSWTBot.getBot(); | |
EnvSetupOperations.setupEspressifEnv(bot); | |
TestWidgetWaitUtility.waitForOperationsInProgressToFinishAsync(bot); | |
} |
private static void whenOpenPartitionTableEditor() throws IOException | ||
{ | ||
ProjectTestOperations.launchCommandUsingContextMenu(projectName, bot, "Partition Table Editor"); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Handle potential exceptions when opening the Partition Table Editor
The method whenOpenPartitionTableEditor
can throw IOException
, but exceptions are not being handled within the method. Consider adding exception handling to ensure that any issues are caught and logged appropriately.
Apply this diff to add exception handling:
private static void whenOpenPartitionTableEditor()
{
- ProjectTestOperations.launchCommandUsingContextMenu(projectName, bot, "Partition Table Editor");
+ try {
+ ProjectTestOperations.launchCommandUsingContextMenu(projectName, bot, "Partition Table Editor");
+ } catch (IOException e) {
+ // Log the exception and handle it accordingly
+ e.printStackTrace();
+ }
}
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
private static void whenOpenPartitionTableEditor() throws IOException | |
{ | |
ProjectTestOperations.launchCommandUsingContextMenu(projectName, bot, "Partition Table Editor"); | |
} | |
private static void whenOpenPartitionTableEditor() | |
{ | |
try { | |
ProjectTestOperations.launchCommandUsingContextMenu(projectName, bot, "Partition Table Editor"); | |
} catch (IOException e) { | |
// Log the exception and handle it accordingly | |
e.printStackTrace(); | |
} | |
} |
public static void deletePartitionTableRow(SWTWorkbenchBot bot) throws IOException | ||
{ | ||
SWTBotTable table = bot.table(); | ||
table.select(1); | ||
bot.toolbarButton("Delete Selected").click(); | ||
bot.button("OK").click(); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add validation in deletePartitionTableRow
To prevent potential exceptions, consider adding a check to ensure that the table has at least two rows before attempting to select and delete a row at index 1.
Apply this diff to add validation:
public static void deletePartitionTableRow(SWTWorkbenchBot bot) throws IOException
{
SWTBotTable table = bot.table();
+ if (table.rowCount() > 1) {
table.select(1);
bot.toolbarButton("Delete Selected").click();
bot.button("OK").click();
+ } else {
+ // Handle the case where there are not enough rows to delete
+ throw new IllegalStateException("Unable to delete row: Table does not have enough rows.");
+ }
}
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
public static void deletePartitionTableRow(SWTWorkbenchBot bot) throws IOException | |
{ | |
SWTBotTable table = bot.table(); | |
table.select(1); | |
bot.toolbarButton("Delete Selected").click(); | |
bot.button("OK").click(); | |
} | |
public static void deletePartitionTableRow(SWTWorkbenchBot bot) throws IOException | |
{ | |
SWTBotTable table = bot.table(); | |
if (table.rowCount() > 1) { | |
table.select(1); | |
bot.toolbarButton("Delete Selected").click(); | |
bot.button("OK").click(); | |
} else { | |
// Handle the case where there are not enough rows to delete | |
throw new IllegalStateException("Unable to delete row: Table does not have enough rows."); | |
} | |
} |
public static boolean checkShellContent(SWTWorkbenchBot bot, String shellName, String expectedText) | ||
{ | ||
SWTBotShell shell = bot.shell(shellName); | ||
shell.activate(); | ||
SWTBotLabel label = bot.label(expectedText); | ||
String actualText = label.getText(); | ||
return expectedText.equals(actualText); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Handle potential exceptions in checkShellContent
The method checkShellContent
may throw a WidgetNotFoundException
if the shell or label with the expected text is not found. To enhance robustness, consider catching this exception and returning false
when the shell or label is not found.
Apply this diff to handle exceptions:
public static boolean checkShellContent(SWTWorkbenchBot bot, String shellName, String expectedText)
{
try {
SWTBotShell shell = bot.shell(shellName);
shell.activate();
SWTBotLabel label = bot.label(expectedText);
String actualText = label.getText();
return expectedText.equals(actualText);
} catch (WidgetNotFoundException e) {
return false;
}
}
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
public static boolean checkShellContent(SWTWorkbenchBot bot, String shellName, String expectedText) | |
{ | |
SWTBotShell shell = bot.shell(shellName); | |
shell.activate(); | |
SWTBotLabel label = bot.label(expectedText); | |
String actualText = label.getText(); | |
return expectedText.equals(actualText); | |
} | |
public static boolean checkShellContent(SWTWorkbenchBot bot, String shellName, String expectedText) | |
{ | |
try { | |
SWTBotShell shell = bot.shell(shellName); | |
shell.activate(); | |
SWTBotLabel label = bot.label(expectedText); | |
String actualText = label.getText(); | |
return expectedText.equals(actualText); | |
} catch (WidgetNotFoundException e) { | |
return false; | |
} | |
} |
public static boolean checkPartitionTableContent(SWTWorkbenchBot bot) | ||
{ | ||
String[] builtInPartitionArray = { "nvs", "phy_init", "factory", "data", "data", "app", "nvs", "phy", "factory", | ||
"0x9000", "0xf000", "0x10000", "0x6000", "0x1000", "1M", "", "", "" }; | ||
int builtInIndex = 0; | ||
SWTBotTable table = bot.table(); | ||
int columns = table.columnCount(); | ||
int rows = table.rowCount(); | ||
if (columns != 6 && rows != 3) | ||
{ | ||
return false; | ||
} | ||
for (int col = 0; col < columns; col++) | ||
{ | ||
for (int row = 0; row < rows; row++) | ||
{ | ||
String tableContent = table.cell(row, col); | ||
|
||
if (!builtInPartitionArray[builtInIndex].equals(tableContent)) | ||
{ | ||
return false; | ||
} | ||
builtInIndex++; | ||
} | ||
} | ||
return true; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Correct the condition and loop order in checkPartitionTableContent
-
Incorrect logical operator in the condition
The condition
if (columns != 6 && rows != 3)
should use the logical OR operator||
to correctly validate the table dimensions. Using&&
means thereturn false
statement will not execute if eithercolumns
equals 6 orrows
equals 3. -
Swap the loop order for proper traversal
The nested loops should iterate over rows first and then columns to access table cells in row-major order, matching the structure of
builtInPartitionArray
.
Apply this diff to correct the issues:
public static boolean checkPartitionTableContent(SWTWorkbenchBot bot)
{
String[] builtInPartitionArray = { "nvs", "phy_init", "factory", "data", "data", "app", "nvs", "phy", "factory",
"0x9000", "0xf000", "0x10000", "0x6000", "0x1000", "1M", "", "", "" };
int builtInIndex = 0;
SWTBotTable table = bot.table();
int columns = table.columnCount();
int rows = table.rowCount();
- if (columns != 6 && rows != 3)
+ if (columns != 6 || rows != 3)
{
return false;
}
- for (int col = 0; col < columns; col++)
+ for (int row = 0; row < rows; row++)
{
- for (int row = 0; row < rows; row++)
+ for (int col = 0; col < columns; col++)
{
String tableContent = table.cell(row, col);
if (!builtInPartitionArray[builtInIndex].equals(tableContent))
{
return false;
}
builtInIndex++;
}
}
return true;
}
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
public static boolean checkPartitionTableContent(SWTWorkbenchBot bot) | |
{ | |
String[] builtInPartitionArray = { "nvs", "phy_init", "factory", "data", "data", "app", "nvs", "phy", "factory", | |
"0x9000", "0xf000", "0x10000", "0x6000", "0x1000", "1M", "", "", "" }; | |
int builtInIndex = 0; | |
SWTBotTable table = bot.table(); | |
int columns = table.columnCount(); | |
int rows = table.rowCount(); | |
if (columns != 6 && rows != 3) | |
{ | |
return false; | |
} | |
for (int col = 0; col < columns; col++) | |
{ | |
for (int row = 0; row < rows; row++) | |
{ | |
String tableContent = table.cell(row, col); | |
if (!builtInPartitionArray[builtInIndex].equals(tableContent)) | |
{ | |
return false; | |
} | |
builtInIndex++; | |
} | |
} | |
return true; | |
} | |
public static boolean checkPartitionTableContent(SWTWorkbenchBot bot) | |
{ | |
String[] builtInPartitionArray = { "nvs", "phy_init", "factory", "data", "data", "app", "nvs", "phy", "factory", | |
"0x9000", "0xf000", "0x10000", "0x6000", "0x1000", "1M", "", "", "" }; | |
int builtInIndex = 0; | |
SWTBotTable table = bot.table(); | |
int columns = table.columnCount(); | |
int rows = table.rowCount(); | |
if (columns != 6 || rows != 3) | |
{ | |
return false; | |
} | |
for (int row = 0; row < rows; row++) | |
{ | |
for (int col = 0; col < columns; col++) | |
{ | |
String tableContent = table.cell(row, col); | |
if (!builtInPartitionArray[builtInIndex].equals(tableContent)) | |
{ | |
return false; | |
} | |
builtInIndex++; | |
} | |
} | |
return true; | |
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
📒 Files selected for processing (1)
- tests/com.espressif.idf.ui.test/src/com/espressif/idf/ui/test/executable/cases/project/NewEspressifIDFProjectSBOMTest.java (1 hunks)
🧰 Additional context used
// @Test | ||
// public void givenNewProjectCreatedBuiltWhenRunSBOMtoolRedirectOutputToFileThenCheckConsoleAndSbomFile() | ||
// throws Exception | ||
// { | ||
// Fixture.givenNewEspressifIDFProjectIsSelected("EspressIf", "Espressif IDF Project"); | ||
// Fixture.givenProjectNameIs("NewProjectSbomThirdTest"); | ||
// Fixture.whenNewProjectIsSelected(); | ||
// Fixture.whenProjectIsBuiltUsingContextMenu(); | ||
// Fixture.whenOpenSbomTool(); | ||
// Fixture.whenRedirectOutputToTheFileClicked(); | ||
// Fixture.whenRunSbomTool(); | ||
// Fixture.thenCheckInConsole(); | ||
// Fixture.whenRefreshProject(); | ||
// Fixture.thenOpenSbomFile(); | ||
// Fixture.thenCheckSbomFile(); | ||
// } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💡 Codebase verification
SBOM tool output redirection lacks active tests.
The test method givenNewProjectCreatedBuiltWhenRunSBOMtoolRedirectOutputToFileThenCheckConsoleAndSbomFile
has been commented out, and no other tests currently cover the functionality of redirecting SBOM tool output to a file. This may lead to unverified behavior in the SBOM feature.
Please address this by either re-enabling the commented-out test or adding new tests to ensure comprehensive coverage of the SBOM tool's output redirection functionality.
🔗 Analysis chain
Clarify the reason for commenting out the test method.
The test method givenNewProjectCreatedBuiltWhenRunSBOMtoolRedirectOutputToFileThenCheckConsoleAndSbomFile
has been commented out. This test appears to cover a specific scenario of redirecting SBOM tool output to a file and verifying the results, which seems important for ensuring the tool's functionality.
Could you please clarify:
- Why was this test method commented out?
- Is the functionality it tests still relevant?
- If so, is this scenario covered by other tests, or should we consider re-enabling this test?
Ensuring comprehensive test coverage is crucial for maintaining the reliability of the SBOM tool feature.
To help verify the current test coverage, you can run the following script:
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash
# Description: Search for tests related to SBOM file output redirection
# Test: Look for other test methods that might cover similar functionality
rg --type java -i "redirect.*output.*file" tests/
Length of output: 1348
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 2
🧹 Outside diff range and nitpick comments (2)
tests/com.espressif.idf.ui.test/src/com/espressif/idf/ui/test/executable/cases/project/NewEspressifIDFProjectTest.java (2)
Line range hint
389-395
: Approve refactoring of component installation methodThe change from
openProjectNewComponentUsingContextMenu
tolaunchCommandUsingContextMenu
appears to be a good refactoring that improves code reusability. This change is approved.However, consider extracting the string "Install New Component" into a constant to improve maintainability and reduce the risk of typos.
Consider applying this change:
+ private static final String INSTALL_NEW_COMPONENT_COMMAND = "Install New Component"; - ProjectTestOperations.launchCommandUsingContextMenu(projectName, bot, "Install New Component"); + ProjectTestOperations.launchCommandUsingContextMenu(projectName, bot, INSTALL_NEW_COMPONENT_COMMAND);
Line range hint
183-395
: Overall feedback: Remove duplicates and focus on meaningful test additionsThe changes in this file primarily consist of adding duplicate test methods, which is not a recommended practice in test development. Here are some suggestions for improvement:
- Remove all duplicate test methods (those with suffix '1').
- If the intention is to increase test coverage, consider adding new test cases that cover different scenarios, edge cases, or potential failure modes.
- Instead of duplicating entire methods, you could parameterize existing tests to cover multiple scenarios.
- The refactoring in the
whenInstallNewComponentUsingContextMenu
method is a good change. Consider applying similar refactoring to other methods if applicable.By focusing on meaningful test additions and avoiding duplication, you can improve the overall quality and maintainability of the test suite.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
📒 Files selected for processing (1)
- tests/com.espressif.idf.ui.test/src/com/espressif/idf/ui/test/executable/cases/project/NewEspressifIDFProjectTest.java (2 hunks)
🧰 Additional context used
@Test | ||
public void givenNewIDFProjectIsSelectedThenProjectIsCreatedAndAddedToProjectExplorer1() throws Exception | ||
{ | ||
Fixture.givenNewEspressifIDFProjectIsSelected("EspressIf", "Espressif IDF Project"); | ||
Fixture.givenProjectNameIs("NewProjectTest"); | ||
Fixture.whenNewProjectIsSelected(); | ||
Fixture.thenProjectIsAddedToProjectExplorer(); | ||
|
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove duplicate test method
This test method is an exact duplicate of givenNewIDFProjectIsSelectedThenProjectIsCreatedAndAddedToProjectExplorer
. Duplicate tests don't add value to the test suite and increase maintenance overhead. Consider removing this method or modifying it to test a different scenario if needed.
Fixture.givenProjectNameIs("NewProjectTestTemplate"); | ||
Fixture.givenProjectTemplateIs("bluetooth/esp_hid_device"); | ||
Fixture.whenProjectIsCreatedFromTemplate(); | ||
Fixture.thenProjectIsAddedToProjectExplorer(); | ||
Fixture.thenProjectHasTheFile("esp_hid_device_main.c", "/main"); | ||
Fixture.thenProjectHasTheFile("esp_hid_gap.c", "/main"); | ||
Fixture.thenProjectHasTheFile("esp_hid_gap.h", "/main"); | ||
} | ||
|
||
@Test | ||
public void givenNewIDFProjectIsCreatedAndBuiltUsingContextMenuOnProjectThenProjectIsCreatedAndBuilt1() | ||
throws Exception | ||
{ | ||
Fixture.givenNewEspressifIDFProjectIsSelected("EspressIf", "Espressif IDF Project"); | ||
Fixture.givenProjectNameIs("NewProjectForContextMenuBuildTest"); | ||
Fixture.whenNewProjectIsSelected(); | ||
Fixture.whenProjectIsBuiltUsingContextMenu(); | ||
Fixture.thenConsoleShowsBuildSuccessful(); | ||
} | ||
|
||
@Test | ||
public void givenNewIDFProjectIsCreatedAndBuiltUsingToolbarButtonThenProjectIsBuilt1() throws Exception | ||
{ | ||
Fixture.givenNewEspressifIDFProjectIsSelected("EspressIf", "Espressif IDF Project"); | ||
Fixture.givenProjectNameIs("NewProjectToolbarBuildButtonTest"); | ||
Fixture.whenNewProjectIsSelected(); | ||
Fixture.whenProjectIsBuiltUsingContextMenu(); | ||
Fixture.thenConsoleShowsBuildSuccessful(); | ||
} | ||
|
||
@Test | ||
public void givenNewProjectCreatedAndRenamedAfterThenProjectIsBuildSuccessfully1() throws Exception | ||
{ | ||
Fixture.givenNewEspressifIDFProjectIsSelected("EspressIf", "Espressif IDF Project"); | ||
Fixture.givenProjectNameIs("NewProjectForRenameTest"); | ||
Fixture.whenNewProjectIsSelected(); | ||
Fixture.whenProjectIsRenamed("NewProjectForRenameTest2"); | ||
Fixture.whenProjectIsBuiltUsingContextMenu(); | ||
Fixture.thenConsoleShowsBuildSuccessful(); | ||
} | ||
|
||
@Test | ||
public void givenNewProjectCreatedDfuBuiltThenHasDfuBin1() throws Exception | ||
{ | ||
Fixture.givenNewEspressifIDFProjectIsSelected("EspressIf", "Espressif IDF Project"); | ||
Fixture.givenProjectNameIs("NewProjectTestDFU"); | ||
Fixture.whenNewProjectIsSelected(); | ||
Fixture.thenLaunchTargetIsSelectedFromLaunchTargets("esp32s2"); | ||
Fixture.turnOnDfu(); | ||
Fixture.whenProjectIsBuiltUsingContextMenu(); | ||
Fixture.thenProjectHasTheFile("dfu.bin", "/build"); | ||
Fixture.turnOffDfu(); | ||
} | ||
|
||
@Test | ||
public void givenNewProjectCreatedThenInstallNewComponent1() throws Exception | ||
{ | ||
Fixture.givenNewEspressifIDFProjectIsSelected("EspressIf", "Espressif IDF Project"); | ||
Fixture.givenProjectNameIs("NewProjectForInstallNewComponentTest"); | ||
Fixture.whenNewProjectIsSelected(); | ||
Fixture.whenProjectIsBuiltUsingContextMenu(); | ||
Fixture.whenInstallNewComponentUsingContextMenu(); | ||
Fixture.whenRefreshProject(); | ||
Fixture.checkIfNewComponentIsInstalledUsingContextMenu(); | ||
} | ||
|
||
@Test | ||
public void givenNewProjectCreatedBuiltAndThenProjectCleanUsingContextMenu1() throws Exception | ||
{ | ||
Fixture.givenNewEspressifIDFProjectIsSelected("EspressIf", "Espressif IDF Project"); | ||
Fixture.givenProjectNameIs("NewProjectCleanTest"); | ||
Fixture.whenNewProjectIsSelected(); | ||
Fixture.whenProjectIsBuiltUsingContextMenu(); | ||
Fixture.whenProjectCleanUsingContextMenu(); | ||
Fixture.whenRefreshProject(); | ||
Fixture.checkIfProjectCleanedFilesInBuildFolder(); | ||
} | ||
|
||
@Test | ||
public void givenNewProjectCreatedBuiltAndThenProjectFullCleanUsingContextMenu1() throws Exception | ||
{ | ||
Fixture.givenNewEspressifIDFProjectIsSelected("EspressIf", "Espressif IDF Project"); | ||
Fixture.givenProjectNameIs("NewProjectFullCleanTest"); | ||
Fixture.whenNewProjectIsSelected(); | ||
Fixture.whenProjectIsBuiltUsingContextMenu(); | ||
Fixture.whenProjectFullCleanUsingContextMenu(); | ||
Fixture.whenRefreshProject(); | ||
Fixture.checkIfProjectFullCleanedFilesInBuildFolder(); | ||
} | ||
|
||
@Test | ||
public void givenNewProjectCreatedBuiltAndThenProjectPythonCleanUsingContextMenu1() throws Exception | ||
{ | ||
Fixture.givenNewEspressifIDFProjectIsSelected("EspressIf", "Espressif IDF Project"); | ||
Fixture.givenProjectNameIs("NewProjectPythonCleanTest"); | ||
Fixture.whenNewProjectIsSelected(); | ||
Fixture.whenProjectIsBuiltUsingContextMenu(); | ||
Fixture.whenProjectPythonCleanUsingContextMenu(); | ||
Fixture.checkPythonCLeanCommandDeleteFolder(); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove all duplicate test methods
All test methods with the suffix '1' (from lines 193 to 297) are exact duplicates of existing test methods. This includes:
givenNewIDFProjectIsSelectedFromTemplateThenProjectIsCreatedAndAddedToProjectExplorerWithRequiredFiles1
givenNewIDFProjectIsCreatedAndBuiltUsingContextMenuOnProjectThenProjectIsCreatedAndBuilt1
givenNewIDFProjectIsCreatedAndBuiltUsingToolbarButtonThenProjectIsBuilt1
givenNewProjectCreatedAndRenamedAfterThenProjectIsBuildSuccessfully1
givenNewProjectCreatedDfuBuiltThenHasDfuBin1
givenNewProjectCreatedThenInstallNewComponent1
givenNewProjectCreatedBuiltAndThenProjectCleanUsingContextMenu1
givenNewProjectCreatedBuiltAndThenProjectFullCleanUsingContextMenu1
givenNewProjectCreatedBuiltAndThenProjectPythonCleanUsingContextMenu1
Duplicating test methods without changes doesn't improve test coverage and increases maintenance overhead. Consider removing these duplicate methods. If the intention is to test different scenarios or edge cases, modify the methods to reflect those specific cases instead of creating exact duplicates.
Description
add Partition Table Editor test cases.
Type of change
Checklist
Summary by CodeRabbit