Skip to content

Instantly share code, notes, and snippets.

View safebear's full-sized avatar

Simon Stratton safebear

View GitHub Profile
@safebear
safebear / TaskRepositoryTest.java
Last active July 11, 2018 13:58
Task Repository Test
package com.safebear.tasklist.repository;
import com.safebear.tasklist.model.Task;
import org.assertj.core.api.Assertions;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest;
import org.springframework.test.context.junit4.SpringRunner;
@safebear
safebear / TaskServiceTest.java
Last active July 11, 2018 13:57
Service Test
package com.safebear.tasklist.service;
import com.safebear.tasklist.model.Task;
import com.safebear.tasklist.repository.TaskRepository;
import org.assertj.core.api.Assertions;
import org.assertj.core.util.Lists;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mockito;
@safebear
safebear / Jenkinsfile
Created July 10, 2018 10:53
Jenkins Stage for Extent reports
stage('cucumber bdd tests') {
steps {
sh 'mvn clean -Dtest=${cuke} test -Ddomain=${domain} -Dport=${test_port} -Dcontext=${context} -Dsleep="0" -Dbrowser="headless"'
}
post {
always {
publishHTML([
@safebear
safebear / RunCukesIT.java
Created July 10, 2018 10:52
Cucumber Runner for Extent Reports
package com.safebear.tasklist.usertests;
import com.cucumber.listener.Reporter;
import cucumber.api.CucumberOptions;
import cucumber.api.junit.Cucumber;
import org.junit.AfterClass;
import org.junit.runner.RunWith;
import java.io.File;
@safebear
safebear / extent-config.xml
Created July 10, 2018 10:50
Extent Config
<?xml version="1.0" encoding="UTF-8"?>
<extentreports>
<configuration>
<!-- report theme --> <!-- standard, dark -->
<theme>standard</theme>
<!-- document encoding --> <!-- defaults to UTF-8 -->
<encoding>UTF-8</encoding>
<!-- protocol for script and stylesheets --> <!-- defaults to https -->
@safebear
safebear / Jenkinsfile
Created July 10, 2018 10:48
Postman Code - API Tests stage
stage('Run API Tests') {
steps {
// sh 'mvn -Dtest=${apiTests} test -Ddomain=${domain} -Dport=${test_port} -Dcontext=${context}'
sh 'newman run src/test/collections/tasklist.postman_collection.json -e src/test/collections/testenv.postman_environment.json --bail newman'
}
// post {
// always {
@safebear
safebear / StepDefs.java
Last active July 10, 2018 08:25
Using a DataTable in Cucumber
@Given("^the following tasks are created:$")
public void the_following_tasks_are_created(DataTable tasks) {
// Here I'm converting the raw data into a list of lists. The inner list contains the data from a row in the table, while the outer list is the list of rows.
List<List<String>> data = tasks.raw();
// Here I'm checking to see if the first task in the first row (x=0,y=0) has already been created in the system. If it has, then I don't create them.
if (!taskListPage.checkForTask(data.get(0).get(0))) {
// Here I'm iterating through the rows in the table and storing each row in a List called 'task' each time.
@safebear
safebear / Jenkinsfile
Created July 10, 2018 08:01
sonarqube
steps {
sh 'mvn clean package sonar:sonar -Dsonar.organization=safebear-student-bitbucket -Dsonar.host.url=https://sonarcloud.io -Dsonar.login=f08a36f3598527bf9b20d9b861b57c0aaa5937e3'
}
@safebear
safebear / TaskServiceImpl.java
Created July 8, 2018 21:30
Task Service Implementation - Java
package com.safebear.tasklist.service;
import com.safebear.tasklist.domain.Task;
import com.safebear.tasklist.repository.TaskRepository;
import org.springframework.stereotype.Service;
@Service
public class TaskServiceImpl implements TaskService {
private TaskRepository taskRepository;
@safebear
safebear / TaskService.java
Created July 8, 2018 21:27
Task Service - TaskList
package com.safebear.tasklist.service;
import com.safebear.tasklist.domain.Task;
public interface TaskService {
Iterable<Task> list();
Task save(Task task);