title: How to configure to execute JUnit test cases using the build.gradle in docker container?
body: <p>I have written JUnit test cases now I want to run those JUnit test cases under docker container with the help of build.gradle file, I am completely new in docker so I have no idea how to configure and run JUnit test cases under docker.
  Here is my gradle file
  Build.gradle</p>
  
  <pre><code>buildscript {
      ext {
          springBootVersion = '1.5.6.RELEASE'
      }
      repositories {
          mavenCentral()
      }
      dependencies {
          classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
          classpath('com.bmuschko:gradle-docker-plugin:3.0.8')
      }
  }
  
  apply plugin: 'java'
  apply plugin: 'eclipse'
  apply plugin: 'org.springframework.boot'
  sourceCompatibility = 1.8
  targetCompatibility = 1.8
  
  task wrapper(type: Wrapper) {
      gradleVersion = '4.1'
  }
  
  jar {
      manifest {
          attributes 'Implementation-Title': 'ProjectName',
                     'Implementation-Version': '1.0'
      }
      archiveName = "project-name-api.jar"
  }
  
  apply plugin: 'org.springframework.boot'
  bootRepackage {
      mainClass = 'com.xxx.xxx.app.TestApiApplication'
  }
  
  repositories {
      mavenCentral()
  }
  
  project.ext {
      springBootVersion = '1.5.6.RELEASE'
      dockerTag = "${System.env.DOCKER_TAG}"
  }
  
  dependencies {
      compile('org.springframework.boot:spring-boot-starter-web-services')
      compile('org.springframework.boot:spring-boot-starter-data-jpa')
      compile('mysql:mysql-connector-java:5.1.6')
      compile('org.quartz-scheduler:quartz:2.2.1')
      compile('org.springframework.boot:spring-boot-starter-actuator')
      compile('org.springframework.boot:spring-boot-starter-security')
      testCompile('org.springframework.boot:spring-boot-starter-test')
  }
  
  apply plugin: 'com.bmuschko.docker-remote-api'
  import com.bmuschko.gradle.docker.tasks.image.*
  
  docker {
      url = 'https://18.20.80.49:1111'
      certPath = new File("${System.env.WORKSPACE}/certs")
      registryCredentials {
          url = 'some url'
          username = 'test'
          password = 'test'
          email = 'test@test.com'
      }
  }
  
  task createDockerfile(type: Dockerfile) {
      destFile = project.file('Dockerfile')
      instruction 'FROM ingensi/oracle-jdk:latest'
      instruction 'EXPOSE 80'
      instruction 'ENV java.net.useSystemProxies true'
      instruction 'ADD build/libs/project-name.jar /opt/'
      instruction 'ENTRYPOINT java -jar $JVM_MIN_MEM $JVM_MAX_MEM -Duser.timezone=UTC -Dhttp.proxyHost=$proxy -Dhttp.proxyPort=$proxy_port -Dhttps.proxyHost=$proxy -Dhttps.proxyPort=$proxy_port /opt/projectname.jar'
  }
  
  task buildImage( type: DockerBuildImage) {
      dependsOn jar
      dependsOn bootRepackage
      dependsOn createDockerfile
      inputDir = createDockerfile.destFile.parentFile
      tag = "path/project-name:$project.dockerTag"
  }
  
  task pushImage( type: DockerPushImage) {
      dependsOn buildImage
      imageName = "path/project-name"
      tag = "$project.dockerTag"
  }
  </code></pre>
  
  <p>and this sample test class which i have written.</p>
  
  <pre><code>@RunWith(SpringRunner.class)
  @SpringBootTest(classes = DepartmentService.class)
  public class DepartmentServiceTest {
      @Autowired
      DepartmentService DepartmentService;
  
      @MockBean
      DepartmentRepository DepartmentRepository;
  
      @MockBean
      DepartmentAndUserHandler departmentAndUserHandler;
      Department ca = new Department();
  
      @Before
      public void initializeDepartment() {
          ca.setId(1);
          ca.setActive(true);
          ca.setSubId(1);
          ca.setCreated(new Timestamp(1l));
          ca.setLastUpdated(new Timestamp(1l));
          ca.setPassword("test");
          ca.setReplicateTimestamp(new Timestamp(1l));
          ca.setUserId(1);
          ca.setUserName("test");
          ca.setUserSecret("test");        
      }    
  
      @Test
      public void testGetDepartment() {
  
          Optional&lt;Department&gt; DepartmentOptional = Optional.of(ca);     
  
          Mockito.when(
                  DepartmentRepository.findByDepartmentIdAndIsActive(Mockito.anyInt(), Mockito.anyBoolean()))
                  .thenReturn(DepartmentOptional);
          Mockito.when(departmentAndUserHandler.createDepartmentAndUser(Mockito.anyInt())).thenReturn(ca);
          Mockito.when(DepartmentRepository.save(ca)).thenReturn(ca);
  
          Department caResponse = DepartmentService.getDepartment(1, 1l, true);
          assertThat(caResponse).isNotNull();
          assertThat(caResponse.getUserId()).isEqualTo(1l);
      }
  
  }
  </code></pre>
  
  <p>Do I need to make some changes under gradle file or else?
  Thank You.</p>