Home | History | Annotate | Download | only in junit
      1 /*
      2  * Copyright (C) 2014 The Android Open Source Project
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *      http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  */
     16 
     17 package com.android.cts.junit;
     18 
     19 import org.junit.runner.Description;
     20 import org.junit.runner.Result;
     21 import org.junit.runner.notification.Failure;
     22 import org.junit.runner.notification.RunListener;
     23 
     24 public class SingleJUnitTestRunListener extends RunListener {
     25     private static class Prefixes {
     26         @SuppressWarnings("unused")
     27         private static final String INFORMATIONAL_MARKER = "[----------]";
     28         private static final String START_TEST_RUN_MARKER = "[==========] Running";
     29         private static final String TEST_RUN_MARKER = "[==========]";
     30         private static final String START_TEST_MARKER = "[ RUN      ]";
     31         private static final String OK_TEST_MARKER = "[       OK ]";
     32         private static final String FAILED_TEST_MARKER = "[  FAILED  ]";
     33     }
     34 
     35     @Override
     36     public void testRunStarted(Description description) throws Exception {
     37     }
     38 
     39     @Override
     40     public void testRunFinished(Result result) throws Exception {
     41         String status = result.wasSuccessful() ? Prefixes.OK_TEST_MARKER
     42                 : Prefixes.FAILED_TEST_MARKER;
     43         System.out.println(status);
     44     }
     45 
     46     @Override
     47     public void testStarted(Description description) throws Exception {
     48         System.out.println(String.format("%s %s.%s", Prefixes.START_TEST_MARKER,
     49                 description.getClassName(), description.getMethodName()));
     50     }
     51 
     52     @Override
     53     public void testFinished(Description description) throws Exception {
     54     }
     55 
     56     @Override
     57     public void testFailure(Failure failure) throws Exception {
     58     }
     59 
     60     @Override
     61     public void testAssumptionFailure(Failure failure) {
     62     }
     63 
     64     @Override
     65     public void testIgnored(Description description) throws Exception {
     66     }
     67 }
     68