Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions com.vogella.tasks.ui.tests/.classpath
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-21"/>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry kind="src" path="src"/>
<classpathentry kind="output" path="bin"/>
</classpath>
45 changes: 45 additions & 0 deletions com.vogella.tasks.ui.tests/.project
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>com.vogella.tasks.ui.tests</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.pde.ManifestBuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.pde.SchemaBuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.m2e.core.maven2Builder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.m2e.core.maven2Nature</nature>
<nature>org.eclipse.pde.PluginNature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
<filteredResources>
<filter>
<id>1749802401051</id>
<name></name>
<type>30</type>
<matcher>
<id>org.eclipse.core.resources.regexFilterMatcher</id>
<arguments>node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__</arguments>
</matcher>
</filter>
</filteredResources>
</projectDescription>
121 changes: 121 additions & 0 deletions com.vogella.tasks.ui.tests/IMPLEMENTATION.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
# Test Plug-in Implementation Summary

## Overview

This document summarizes the implementation of the new test plug-in `com.vogella.tasks.ui.tests` for the `com.vogella.tasks.ui` RCP application.

## What Was Implemented

### 1. Test Plug-in Structure

Created a new test plug-in with the following structure:

```
com.vogella.tasks.ui.tests/
├── META-INF/
│ └── MANIFEST.MF # Bundle manifest with dependencies
├── src/
│ └── com/vogella/tasks/ui/tests/
│ ├── LoginTestHelper.java # Utility for login bypass
│ ├── MenuStructureTest.java # Menu structure tests
│ └── UIStructureTest.java # UI structure tests
├── .classpath # Eclipse classpath configuration
├── .project # Eclipse project configuration
├── build.properties # Build configuration
└── README.md # Documentation
```

### 2. Test Classes

**MenuStructureTest.java**
- Tests that all main menus exist (File, Edit, Window, Processes)
- Verifies menu items like Save, Perspectives submenu, Theme submenu
- Uses SWTBot for UI interaction

**UIStructureTest.java**
- Tests application window existence
- Verifies basic application structure
- Demonstrates E4 application model access patterns

**LoginTestHelper.java**
- Utility class to control login behavior
- Provides methods to enable/disable login bypass
- Uses system property `skipLogin` for configuration

### 3. Login Bypass Mechanism

Added `LoginAddon.java` to the main application (`com.vogella.tasks.ui`):
- Shows an informational login dialog on startup
- Respects the `skipLogin` system property
- Can be bypassed by setting `-DskipLogin=true`
- Demonstrates how to implement authentication that can be disabled for testing

### 4. Build Integration

- Added test plug-in to `pom.xml` modules list
- Configured `build.properties` with:
- UI harness and UI thread settings
- Product ID: `com.vogella.tasks.ui.product`
- Argument line with `skipLogin` property
- Updated `target-platform.target` with JUnit platform dependencies:
- junit-jupiter-api
- junit-jupiter-engine
- junit-platform-suite-api
- junit-platform-suite-engine
- junit-vintage-engine

### 5. Dependencies

The test plug-in depends on:
- JUnit 5 (Jupiter) for test framework
- SWTBot for UI testing (e4.finder and swt.finder)
- Eclipse E4 workbench bundles
- com.vogella.tasks.ui bundle (the application under test)

## Running Tests

### Compilation
Tests compile successfully as part of the regular build:
```bash
mvn clean verify -DskipTests
```

### Execution
Tests require a graphical display to run. On Linux with Xvfb:
```bash
Xvfb :99 -screen 0 1024x768x24 &
export DISPLAY=:99
mvn clean verify
```

## Limitations

1. **Display Requirement**: UI tests need a graphical display (X11 on Linux, native display on Windows/Mac)
2. **CI/CD Integration**: In headless CI environments, use `-DskipTests` or configure Xvfb
3. **Product Configuration**: The global tycho-surefire configuration needs adjustment per test plugin
4. **Test Coverage**: Current tests demonstrate the framework; additional tests can be added for specific features

## How to Add More Tests

1. Create new test classes in `src/com/vogella/tasks/ui/tests/`
2. Use JUnit 5 annotations: `@Test`, `@BeforeEach`, `@AfterEach`
3. Use SWTBot for UI interaction:
```java
SWTBot bot = new SWTBot();
bot.menu("File").menu("Save").click();
```
4. Access E4 model elements via injection in tests (advanced)

## Testing Approach

The tests follow Eclipse RCP best practices:
- Use SWTBot for UI widget interaction
- Use standard Platform API for application model access
- Provide bypass mechanisms for authentication/login
- Support both interactive and CI/CD testing scenarios

## Documentation

- `README.md` in the test plug-in provides user-facing documentation
- Code comments explain the purpose of each test class
- This summary document explains the implementation details
19 changes: 19 additions & 0 deletions com.vogella.tasks.ui.tests/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: Tasks UI Tests
Bundle-SymbolicName: com.vogella.tasks.ui.tests
Bundle-Version: 1.0.0.qualifier
Bundle-Vendor: VOGELLA
Import-Package: org.junit.jupiter.api;version="5.12.2"
Bundle-RequiredExecutionEnvironment: JavaSE-21
Require-Bundle: org.eclipse.swt,
org.eclipse.jface,
org.eclipse.swtbot.e4.finder;bundle-version="4.3.0",
org.eclipse.swtbot.swt.finder;bundle-version="4.3.0",
org.slf4j.api;bundle-version="1.7.30",
com.vogella.tasks.ui;bundle-version="1.0.0",
org.eclipse.e4.ui.workbench,
org.eclipse.e4.core.di,
org.eclipse.e4.ui.model.workbench,
org.eclipse.e4.core.contexts
Automatic-Module-Name: com.vogella.tasks.ui.tests
96 changes: 96 additions & 0 deletions com.vogella.tasks.ui.tests/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
# Tasks UI Tests

This test plug-in contains automated tests for the `com.vogella.tasks.ui` RCP application.

## Important: Build Configuration

**Note:** This test plug-in is commented out in the main `pom.xml` by default, similar to other UI test plugins in this repository. UI tests require a graphical display and can be unreliable in CI environments even with Xvfb.

To enable the tests, uncomment the module in `pom.xml`:
```xml
<module>com.vogella.tasks.ui.tests</module>
```

## Features

- **Menu Structure Tests**: Verifies that all expected menus are present and accessible
- **UI Structure Tests**: Tests the application window and UI components
- **Login Bypass**: Provides a mechanism to skip login dialogs during testing

## Running the Tests

### Option 1: Run tests in Eclipse IDE
1. Import the test plugin into Eclipse
2. Right-click on a test class
3. Select "Run As" > "JUnit Plug-in Test"

### Option 2: Build with Maven (requires display)

First, uncomment the test module in `pom.xml`, then:

**On Linux with Xvfb (X virtual framebuffer):**

```bash
Xvfb :99 -screen 0 1024x768x24 &
export DISPLAY=:99
mvn clean verify
```

**On systems with a display:**
```bash
mvn clean verify
```

**To compile without running tests:**
```bash
mvn clean verify -DskipTests
```

## Bypassing Login Screen

To bypass the login screen during testing, set the system property `skipLogin` to `true`:

```
-DskipLogin=true
```

This is automatically configured in the test plug-in's build.properties and will be passed to tests when they run.

You can also configure this in:
1. Eclipse Run Configuration (VM arguments: `-DskipLogin=true`)
2. Programmatically using `LoginTestHelper.enableSkipLogin()`

## Test Classes

- `MenuStructureTest`: Tests the menu structure of the application
- `UIStructureTest`: Tests the UI structure and components
- `LoginTestHelper`: Utility class for controlling login behavior in tests

## Login Addon

The main application includes a `LoginAddon` class that demonstrates how to show a login dialog on startup. This addon respects the `skipLogin` system property, making it easy to bypass for automated testing.

## Dependencies

The test plug-in requires:
- JUnit 5 (Jupiter)
- SWTBot for UI testing
- Eclipse E4 RCP bundles
- com.vogella.tasks.ui bundle

## CI/CD Integration

For CI/CD pipelines:
1. Keep the test module commented out in `pom.xml` (default)
2. Tests can still be run manually in Eclipse for development
3. This prevents build failures due to display/UI issues in CI

## Why Tests Are Disabled by Default

UI tests in Eclipse RCP applications:
- Require a graphical display (X11 on Linux, native display on Windows/Mac)
- Can be flaky even with Xvfb due to timing issues
- May fail with different window managers or display configurations
- Are better run interactively during development

For these reasons, UI tests are disabled in the CI build but remain available for local testing and development.
8 changes: 8 additions & 0 deletions com.vogella.tasks.ui.tests/build.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
source.. = src/
output.. = bin/
bin.includes = META-INF/,\
.
pom.model.property.tycho.surefire.useUIHarness = true
pom.model.property.tycho.surefire.useUIThread = true
pom.model.property.tycho.surefire.product = com.vogella.tasks.ui.product
pom.model.property.tycho.surefire.argLine = -DskipLogin=true
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package com.vogella.tasks.ui.tests;

/**
* Utility class to control login behavior for testing.
*
* When running tests, set the system property "skipLogin" to "true" to bypass
* any login dialogs:
*
* -DskipLogin=true
*
* This can also be used programmatically by setting:
* System.setProperty("skipLogin", "true");
*/
public class LoginTestHelper {

private static final String SKIP_LOGIN_PROPERTY = "skipLogin";

/**
* Check if login should be skipped (for testing purposes).
* @return true if the skipLogin system property is set to "true"
*/
public static boolean shouldSkipLogin() {
return "true".equalsIgnoreCase(System.getProperty(SKIP_LOGIN_PROPERTY));
}

/**
* Enable skipping login dialogs for testing.
*/
public static void enableSkipLogin() {
System.setProperty(SKIP_LOGIN_PROPERTY, "true");
}

/**
* Disable skipping login dialogs (restore normal behavior).
*/
public static void disableSkipLogin() {
System.clearProperty(SKIP_LOGIN_PROPERTY);
}
}
Loading
Loading