Re: Custom classloader

"Bill Shannon [email protected] [junit]" <[email protected]> Tue, 19 May 2015 21:17:48 -0700
Newsgroups gmane.comp.java.junit.user
Message-ID <[email protected]>
--------------000703050007030604050906
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Right, even though they're probably loaded in a ClassLoader that JUnit is using,
they're also loaded in a ClassLoader I create, along with other classes being
tested.  My ClassLoader loads its own classes in preference to its parent's
classes, which is the opposite of what's normally done.  It's kind of a cheat
the way it finds the classpath entries to create the ClassLoader, but it works
for my cases - JUnit run by Maven.

Johannes Ernst [email protected] [junit] wrote on 05/19/2015 02:37 PM:
>  
>
> How sneaky! I didn’t think of that approach. You basically ignore the classes
> that junit handed you, and load them yourself?
>
>
>> On May 19, 2015, at 13:53, Bill Shannon [email protected]
>> <mailto:[email protected]> [junit] <[email protected]
>> <mailto:[email protected]>> wrote:
>>
>> I created a ClassLoaderSuite
>> <https://java.net/projects/javamail/sources/mercurial/content/mail/src/test/java/com/sun/mail/test/ClassLoaderSuite.java> to
>> do this for JavaMail testing several years ago.
>>
>> David Saff [email protected] [junit] wrote on 05/19/15 11:01:
>>
>>>  
>>> You should be able to do it with a custom Runner.  As Aaron pointed out,
>>> Robolectric does it, and I'd definitely recommend poking around their code a
>>> bit.  I don't think any patches to JUnit should be necessary.
>>>
>>> On Tue, May 19, 2015 at 7:11 AM, Malte
>>> Finsterwalder [email protected]
>>> <mailto:[email protected]> [junit] <[email protected]
>>> <mailto:[email protected]>> wrote:
>>>
>>>      
>>>     Hi Johannes,
>>>
>>>     I'm totally on Dawids side: Why do you need custom classloading?
>>>     On the other hand, if you really, really need it, you may be able to
>>>     realize it by wrapping surefire or JUnit (or both) somehow. And there is
>>>     always bytecode-manipulation. :-)
>>>     But then again: JUnit is no magic. You could even write your own very
>>>     simple test execution framework for your particular problem. And you
>>>     could even base it on JUnits capabilities.
>>>     Just to spray some more ideas...
>>>
>>>     Greetings,
>>>        Malte
>>>     ​
>>>
>>>
>>
>>
>
> 


--------------000703050007030604050906
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: 8bit





<head>

<style type="text/css">
<!--

/* start of attachment style */
       .ygrp-photo-title{
         clear: both;
         font-size: smaller;
         height: 15px;
         overflow: hidden;
         text-align: center;
         width: 75px;
       }
       div.ygrp-photo{
         background-position: center;
         background-repeat: no-repeat;
         background-color: white;
         border: 1px solid black;
         height: 62px;
         width: 62px;
       }

       div.photo-title 
         a,
         div.photo-title a:active,
         div.photo-title a:hover,
         div.photo-title a:visited {
           text-decoration: none; 
       }

       div.attach-table div.attach-row {
         clear: both;
       }

       div.attach-table div.attach-row div {
         float: left;
         /* margin: 2px;*/
       }

       p {
         clear: both;
         padding: 15px 0 3px 0;
	 overflow: hidden;
       }

       div.ygrp-file {
         width: 30px;
         valign: middle;
       }
       div.attach-table div.attach-row div div a {
         text-decoration: none;
       }

       div.attach-table div.attach-row div div span {
         font-weight: normal;
       }

       div.ygrp-file-title {
         font-weight: bold;
       }
 /* end of attachment style */
        -->
        </style>
        </head>
<html>
  <head>
    <meta content="text/html; charset=UTF-8" http-equiv="Content-Type">
  </head>
  <body bgcolor="#FFFFFF" text="#000000">


<!-- |**|begin egp html banner|**| -->

<br><br>

<!-- |**|end egp html banner|**| -->



    <div class="moz-cite-prefix">Right, even though they're probably
      loaded in a ClassLoader that JUnit is using, they're also loaded
      in a ClassLoader I create, along with other classes being tested. 
      My ClassLoader loads its own classes in preference to its parent's
      classes, which is the opposite of what's normally done.  It's kind
      of a cheat the way it finds the classpath entries to create the
      ClassLoader, but it works for my cases - JUnit run by Maven.<br>
      <br>
      Johannes Ernst <a class="moz-txt-link-abbreviated" href="mailto:[email protected]">[email protected]</a> [junit] wrote on
      05/19/2015 02:37 PM:<br>
    </div>
    <blockquote
      cite="mid:[email protected]"
      type="cite"> <span style="display:none"> </span>
      
          <div id="ygrp-text">
            <p>How sneaky! I didn’t think of that approach. You
              basically ignore the classes that junit handed you, and
              load them yourself?</p>
            <div class=""><br class="">
              <div>
                <blockquote type="cite" class="">
                  <div class="">On May 19, 2015, at 13:53, Bill Shannon
                    <a moz-do-not-send="true"
                      href="mailto:[email protected]" class="">[email protected]</a>
                    [junit] &lt;<a moz-do-not-send="true"
                      href="mailto:[email protected]" class="">[email protected]</a>&gt;
                    wrote:</div>
                  <br class="Apple-interchange-newline">
                  <div class="">
                    <div id="ygrp-mlmsg" style="font-size:
                      13px;font-family: Arial, helvetica, clean,
                      sans-serif;font-style: normal;font-variant:
                      normal;font-weight: normal;letter-spacing:
                      normal;text-align: start;text-indent:
                      0px;text-transform: none;white-space: normal;"
                      class="">
                      <div id="ygrp-msg" class="">
                        <div id="ygrp-text" style="font-family:
                          Georgia;" class="">
                          <p style="margin: 0px 0px 1em;" class="">I
                            created a<span class="Apple-converted-space"> </span><a
                              moz-do-not-send="true"
href="https://java.net/projects/javamail/sources/mercurial/content/mail/src/test/java/com/sun/mail/test/ClassLoaderSuite.java"
                              style="font-family: Verdana;" class="">ClassLoaderSuite</a><span
                              class="Apple-converted-space"> </span>to
                            do this for JavaMail testing several years
                            ago.<br class="">
                            <br class="">
                            David Saff<span
                              class="Apple-converted-space"> </span><a
                              moz-do-not-send="true"
                              class="moz-txt-link-abbreviated"
                              href="mailto:[email protected]"
                              style="font-family: Verdana;">[email protected]</a><span
                              class="Apple-converted-space"> </span>[junit]
                            wrote on 05/19/15 11:01:</p>
                          <blockquote
cite="mid:CALrw-PxDQ7Ef63yrWU_+6ftaCfAhFYwZaBjsqPNxX1eUj8WzQw@mail.gmail.com"
                            type="cite" style="margin: 0px 0px 0px 4px;"
                            class=""><span class=""> </span>
                            <div id="ygrp-text" style="font-family:
                              Georgia;" class="">
                              <div dir="ltr" class="">You should be able
                                to do it with a custom Runner.  As Aaron
                                pointed out, Robolectric does it, and
                                I'd definitely recommend poking around
                                their code a bit.  I don't think any
                                patches to JUnit should be necessary.</div>
                              <div class="gmail_extra"><br class="">
                                <div class="gmail_quote">On Tue, May 19,
                                  2015 at 7:11 AM, Malte Finsterwalder<span
                                    class="Apple-converted-space"> </span><a
                                    moz-do-not-send="true" moz="true"
                                    href="mailto:[email protected]"
                                    class="">[email protected]</a><span
                                    class="Apple-converted-space"> </span>[junit]<span
                                    class="Apple-converted-space"> </span><span
                                    dir="ltr" class="">&lt;<a
                                      moz-do-not-send="true" moz="true"
href="mailto:[email protected]" target="_blank" class="">[email protected]</a>&gt;</span><span
                                    class="Apple-converted-space"> </span>wrote:<br
                                    class="">
                                  <blockquote class="gmail_quote"
                                    style="margin: 0px 0px 0px
                                    4px;border-left-width:
                                    1px;border-left-color: rgb(204, 204,
                                    204);border-left-style: solid;">
                                    <div style="background-color:
                                      rgb(255, 255, 255);" class=""><span
                                        class=""> </span>
                                      <div class="">
                                        <div class="">
                                          <div class="">
                                            <div dir="ltr" class="">Hi
                                              Johannes,
                                              <div class=""><br class="">
                                              </div>
                                              <div class="">I'm totally
                                                on Dawids side: Why do
                                                you need custom
                                                classloading?</div>
                                              <div class="">On the other
                                                hand, if you really,
                                                really need it, you may
                                                be able to realize it by
                                                wrapping surefire or
                                                JUnit (or both) somehow.
                                                And there is always
                                                bytecode-manipulation.
                                                :-)</div>
                                              <div class="">But then
                                                again: JUnit is no
                                                magic. You could even
                                                write your own very
                                                simple test execution
                                                framework for your
                                                particular problem. And
                                                you could even base it
                                                on JUnits capabilities.</div>
                                              <div class="">Just to
                                                spray some more ideas...</div>
                                              <div class=""><br class="">
                                              </div>
                                              <div class="">Greetings,</div>
                                              <div class="">   Malte</div>
                                              ​</div>
                                          </div>
                                        </div>
                                      </div>
                                    </div>
                                  </blockquote>
                                </div>
                                <br class="">
                              </div>
                            </div>
                          </blockquote>
                          <br class="">
                          <div style="margin: 0px 0px 1em;" class=""><br
                              class="webkit-block-placeholder">
                          </div>
                        </div>
                      </div>
                    </div>
                  </div>
                </blockquote>
              </div>
              <br class="">
            </div>
          </div>
          
      
      <!-- end group email -->
    </blockquote>
    <br>
  



<!-- |**|begin egp html banner|**| -->

<br>


<br>

<!-- |**|end egp html banner|**| -->


<div width="1" style="color: white; clear: both;"/>__._,_.___</div>

      
  

    
    <div id="fromDMARC" style="clear:both; margin-top: 10px;">
         <hr style="height:2px ; border-width:0; color:#E3E3E3; background-color:#E3E3E3;">
         Posted by: Bill Shannon &lt;[email protected]&gt;         <hr style="height:2px ; border-width:0; color:#E3E3E3; background-color:#E3E3E3;">
    </div>
<!-- Start Recommendations -->
<!-- End Recommendations -->



<!-- |**|begin egp html banner|**| -->

  <img src="http://geo.yahoo.com/serv?s=97476590/grpId=2423328/grpspId=1705006905/msgId=24664/stime=1432095656" width="1" height="1"> <br>

<!-- |**|end egp html banner|**| -->

    
<!-- |**|begin egp html banner|**| -->

<br>



   
     
 
        <!-- |**|begin egp html banner|**| -->
        <div id="ygrp-vital" style="background-color: #f2f2f2; font-family: Verdana; font-size: 10px; margin-bottom: 10px; padding: 10px;">

        <span id="vithd" style="font-weight: bold; color: #333; text-transform: uppercase; "><a href="https://groups.yahoo.com/neo/groups/junit/info;_ylc=X3oDMTJldDNyODZsBF9TAzk3MzU5NzE0BGdycElkAzI0MjMzMjgEZ3Jwc3BJZAMxNzA1MDA2OTA1BHNlYwN2dGwEc2xrA3ZnaHAEc3RpbWUDMTQzMjA5NTY1Ng--" style="text-decoration: none;">Visit Your Group</a></span>

     <ul style="list-style-type: none; margin: 0; padding: 0; display: inline;">
            <li style="border-right: 1px solid #000; font-weight: 700; display: inline; padding: 0 5px; margin-left: 0;">
      <span class="cat"><a href="https://groups.yahoo.com/neo/groups/junit/members/all;_ylc=X3oDMTJmbmlqanBkBF9TAzk3MzU5NzE0BGdycElkAzI0MjMzMjgEZ3Jwc3BJZAMxNzA1MDA2OTA1BHNlYwN2dGwEc2xrA3ZtYnJzBHN0aW1lAzE0MzIwOTU2NTY-" style="text-decoration: none;">New Members</a></span>
      <span class="ct" style="color: #ff7900;">4</span>
    </li>
                                              </ul>
  </div>


<div id="ft" style="font-family: Arial; font-size: 11px; margin-top: 5px; padding: 0 2px 0 0; clear: both;">
  <a href="https://groups.yahoo.com/neo;_ylc=X3oDMTJkaWg5Z2xiBF9TAzk3NDc2NTkwBGdycElkAzI0MjMzMjgEZ3Jwc3BJZAMxNzA1MDA2OTA1BHNlYwNmdHIEc2xrA2dmcARzdGltZQMxNDMyMDk1NjU2" style="float: left;"><img src="http://l.yimg.com/ru/static/images/yg/img/email/new_logo/logo-groups-137x15.png" height="15" width="137" alt="Yahoo! Groups" style="border: 0;"/></a>
  <div style="color: #747575; float: right;"> &bull; <a href="https://info.yahoo.com/privacy/us/yahoo/groups/details.html" style="text-decoration: none;">Privacy</a> &bull; <a href="mailto:[email protected]?subject=Unsubscribe" style="text-decoration: none;">Unsubscribe</a> &bull; <a href="https://info.yahoo.com/legal/us/yahoo/utos/terms/" style="text-decoration: none;">Terms of Use</a> </div>
</div>

<!-- |**|end egp html banner|**| -->

  </div> <!-- ygrp-msg -->

   


  <br>

<!-- |**|end egp html banner|**| -->


<div style="color: white; clear: both;"/>__,_._,___</div>
</body>
</html>

--------------000703050007030604050906--