Integrating Cucumber into a test framework? - java

I have written a Test framework (that supports Selenuim).
The way it works is such that when I create a test I only have to extend the base class..
class NewTest extend BaseTest {
#Test
public ABC() {
this.sel.driver. ....
}
}
My question is how to integrate Cucumber into my framework, where the Framework is the provider of the Selenium driver, db connections,screenshots, ...etc
The idea is to make it in a way that it does not interfere with the Cucumber normal flow of programming.
Also I'm using maven and junit.

#Test is for Junit not for cucumber.
Cucumber using gherkin language
You can check the setup and usage of cucumber from below tutorial
https://www.toolsqa.com/cucumber-tutorial/
My question is how to integrate Cucumber into my framework, where the
Framework is the provider of the Selenium driver, db
connections,screenshots, ...etc
Just create an package and add your classes like db, selenium etc into it, call them in script as we did in normal framework.
Note that cucumber just provide a flow to run the project from feature and using hook. so learn and did poc in cucumber and you will understand where you need to call what.

Related

void method in Java Integration Tests

I have some experience with Unit Tests in Java and now started to write Integration Tests. However, I have some troubles understanding the Integration Test and writing test. Here are some issues that I would like to be clarified:
1. In my Java (based on Spring Boot) project, should I write Integration Test for Controllers or may it be also ok to write Integration Test for Services also (because there are some methods that are not called from Controller).
2. How can I test a void in service by Integration Test? I have not found a proper example on the web and I thought there is no need or way to test void via Integration Test. Any clarification pls?
OK, so here are the best practices in the area.
should I write Integration Test for Controllers or may it be also ok to write Integration Test for Services also
Most of the integration tests run for services. This is because each service can support several controllers and multiple interfaces in general. For controllers you do just the happy path tests on an integration level.
Any tests for controller specific exceptions go into the controller unit test, where you mock out the service.
How can I test a void in service by Integration Test?
You check its side effect. For example, you use a repository class to see if the relevant data has been persisted to the database.
Does this solve your problem ? Let me know in the comments.

How to keep Maven integration tests isolated from each other?

I have multiple Maven integration tests that are updating the the state of the database, which could create conflicts between these tests. I was wondering if there is a way to isolate these integration tests by leveraging Maven phases or any other approach? Ideally, I would like to have a way to run database migrations before every integration test class. I am using Flyway as the migration tool for my PostgreSQL database and I am using JUnit 4.12. The migrations that I am running are basically creating and populating tables with data for testing.
Junit has #Before and #After annotations to let it invoke methods before and after each test class.
Those methods are then responsible for bringing the database into a known state before each test.
Responsibilities of Maven is to run tests one by one on integration-tests phase, and check results on verify. It also able to prepare/shutdown environment. Check failsafe plugin.
And all isolation between tests is a responsibility of a test framework you use (JUnit, TestNG, Cucumber, etc.).
I was able to solve this using flyway-core. Basically I ended up doing the following inside each of the test classes:
#BeforeClass
public static void migrateDB(){
Flyway flyway = Flyway.configure().dataSource(url, user, password).load();
flyway.clean();
flyway.migrate();
}

About application testing on Java Application

I am doing load test on my server and using JMeter. Do I have any difference choice??
How can I do integration test and How can I do it? Is there any tool?
I know the concept but I dont know how to apply on my project.
My company required me to do a report on load test. Is there any standard on testing? Such as need to use 50 people access and plot the graph of response time?
Sorry I am new to System analyst.
Junit is a framework to support test cases it doesn't provide the tests themselves.
Load testing tends to be specific to the application so you can use JUnit to support that
but you will have to write the tests yourself.
you could look at jMeter or LoadUI

running a geb test from a java class

I've recently stumbled across geb and it looks like a good way to perform integration tests on our web applications. Our platforms are all java based and from reading that
"Geb provides first class support for functional web testing via
integration with popular testing frameworks such as ...JUnit,
TestNG..."
i assumed it would be easy to execute a test from a java class (testng test?).
I'm new to groovy and geb.
So far I have included geb-testng and groovy in my pom:
<dependency>
<groupId>org.codehaus.geb</groupId>
<artifactId>geb-testng</artifactId>
<version>0.7.0</version>
</dependency>
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy</artifactId>
<version>1.8.6</version>
</dependency>
... However i can't find any examples of creating a test and running it from a java class.
help appreciated.
Geb is designed for, and can only be used from, Groovy code. This is mainly due to the dynamic nature of its APIs. What you can choose is which test framework to use (JUnit, TestNG, Spock, etc.). As Geb itself is just a library, it can also be used without a test framework, for example to automate an interaction with a website.
If you need to stick to Java, you'll have to use something like Selenium2, which is what Geb uses under the covers.
I stumpled upon this question while searching a Geb-TestNG example. Here is what is working for me:
import geb.testng.GebTest
import org.testng.annotations.Test
class GroovyYourTestClass extends GebTest {
#Test
void "should test something"() {
to YourPageObject
// ...
}
}
The best alternative to Geb if you're using Java is IMHO Selenide (http://selenide.org)
example from Quick Start Guide:
#Test
public void userCanLoginByUsername() {
open("/login");
$(By.name("user.name")).setValue("johny");
$("#submit").click();
$(".loading_progress").should(disappear); // Waits until element disappears
$("#username").shouldHave(text("Hello, Johny!")); // Waits until element gets text
}
It's independent from your testing framework and therefore can be used with e.g. JUnit, TestNG, Cucumber, ScalaTest, JBehave

Integration of Junit4 with Jmeter

A test suite has been developed using WebDriver and JUnit4. Its working fine, but now we need to integrate test suite with Jmeter for load testing. The problem is that the classes use the Annotation of "#RunsWith" to test a test case with multiple inputs and JMeter does not support this annotation.
Is there any workaround available ? (I could not find any, but may be some one has tried something)
Is this really a good approach, to first write test cases using web driver
Maybe, you just has old version of JMeter that works only with JUnit 3.x. In such a case you have only 2 choses: rewerite your JUnit in 3.x style or upgrade JMeter.

Categories

Resources