> Markdown version of [Set Up Browserless Tests in Plain Java](https://vaadin.com/docs/next/building-apps/testing/browserless/setup-without-spring). Section index: [llms.txt](https://vaadin.com/docs/next/building-apps/llms.txt)

# Set Up Browserless Tests in Plain Java

Use this setup when the view and its collaborators can be constructed without a dependency injection container. Tests extend `BrowserlessTest`, which creates the Vaadin environment but no dependency injection container. For Java EE/CDI injection, use [the CDI setup](https://vaadin.com/docs/next/building-apps/testing/browserless/setup-cdi.md); for Quarkus, use [the Quarkus setup](https://vaadin.com/docs/next/building-apps/testing/browserless/setup-quarkus.md).

## <a id="add-dependencies"></a>Add Dependencies

Assuming you’ve imported the Vaadin Bill-of-Materials (BOM) and have a Maven project, add the `browserless-test-junit6` dependency with a `test` scope:

```xml
<dependency>
    <groupId>com.vaadin</groupId>
    <artifactId>browserless-test-junit6</artifactId>
    <scope>test</scope>
</dependency>
```

No other test framework dependencies are required.

## <a id="create-a-test"></a>Create a Test

Create this view:

`HelloWorldView.java`

```java
import com.vaadin.flow.component.button.Button;
import com.vaadin.flow.component.notification.Notification;
import com.vaadin.flow.component.orderedlayout.HorizontalLayout;
import com.vaadin.flow.component.textfield.TextField;
import com.vaadin.flow.router.Route;

@Route("")
public class HelloWorldView extends HorizontalLayout {

    TextField name;
    Button sayHello;

    public HelloWorldView() {
        name = new TextField("Your name");
        sayHello = new Button("Say hello");
        sayHello.addClickListener(e -> {
            Notification.show("Hello " + name.getValue());
        });
        add(name, sayHello);
    }
}
```

Create a test class that extends `BrowserlessTest`, in the same Java package as the view under `src/test/java`:

`HelloWorldViewTest.java`

```java
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import com.vaadin.browserless.BrowserlessTest;
import com.vaadin.flow.component.notification.Notification;

class HelloWorldViewTest extends BrowserlessTest {

    @Test
    public void setText_clickButton_notificationIsShown() {
        final HelloWorldView helloView = navigate(HelloWorldView.class);

        test(helloView.name).setValue("Test");
        test(helloView.sayHello).click();

        Notification notification = find(Notification.class).single();
        Assertions.assertEquals("Hello Test", test(notification).getText());
    }

}
```

See [How a Browserless Test Works](https://vaadin.com/docs/next/building-apps/testing/browserless/test-user-interactions.md#how-a-browserless-test-works) for what each line of the test does.

## <a id="run-the-test"></a>Run the Test

Run the test from your IDE or with `mvn test`. The test passes when entering a name and clicking the button shows the expected notification.

## <a id="use-an-extension-instead-of-a-base-class"></a>Use an Extension Instead of a Base Class

If your test class already extends another class, register an instance of `BrowserlessExtension` instead. It’s included in the same dependency.

`CartViewExtensionTest.java`

```java
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;
import com.vaadin.browserless.BrowserlessExtension;
import com.vaadin.browserless.ViewPackages;

@ViewPackages(classes = CartView.class)
class CartViewExtensionTest {

    @RegisterExtension
    BrowserlessExtension ext = new BrowserlessExtension();

    @Test
    void addItemToCart() {
        ext.navigate(CartView.class);
        ext.findButton().withText("Add to cart").click();

        Assertions.assertEquals("1 item",
                ext.findSpan().withId("cart-size").getText());
    }
}
```

Call the methods on the extension instance to navigate and interact with components. The example assumes a `CartView` with an **Add to cart** button and a span with the ID `cart-size` that shows the number of items. For lifecycle and configuration options, see [JUnit 6 Extensions](https://vaadin.com/docs/next/flow/testing/browserless/extensions.md).

## <a id="next-steps"></a>Next Steps

- [Test User Interactions](https://vaadin.com/docs/next/building-apps/testing/browserless/test-user-interactions.md) explains how the test works and how to cover more complex views.

- [Debug a Failing Browserless Test](https://vaadin.com/docs/next/building-apps/testing/browserless/debug-tests.md) helps when a test fails.

`D68CAC9E-6131-45C9-84E6-6D1CA1E44E81`
