Skip to content
Ben Weese edited this page Jun 12, 2019 · 4 revisions

JUnit Runner

We create this runner once and use it to run all our test. There is no need to edit this again and it will just be called via maven or on our own when we want to run it thru our IDE.

Below is pretty much all the JUnit I use. We need it so our test can fail or pass but in the end we don't need anything more. Recruiters will ask you if you know JUnit when all you use is this. I don't know why they ask but they do and the person who should be unit testing is the developer not the QA.

package TestRunner;

import org.junit.runner.RunWith;
import cucumber.api.CucumberOptions;
import cucumber.api.junit.Cucumber;

//This is the JUnit Runner for our test.
//We are using Cucumber.
@RunWith(Cucumber.class)
//We define where the Cucumber framework is located and where our code is.
@CucumberOptions(features="src/test/resources/Features",glue={"StepDefinition"})

public class runner {

}

import org.junit.Assert;

Asserts they make the test world go round.

Assert.assertEquals(url, driver.getCurrentUrl());

All this does is compare 2 things and passes of they are equal. In this case it looks at a variable that is set as a string and compares it to the current URL we are on.

Assert.assertTrue(button.isDisplayed());

This Assert just checks if the statement inside is true. The code above looks a WebElement button and sees if it is displayed.

Assert.assertNotNull(driver.findElement(comPOM.capAnswer).getAttribute("value"));

This makes sure that the value of a text box is not null. The Assert it self just checks if the thing is null.