wtorek, 10 sierpnia 2010

Pisanie testów w groovym i Netbeansie

Netbeans (nawet najnowszy 6.9.1) ma błąd, który "psuje" plik antowy jeżeli chcemy wrzucać klasy Grooviego do testów. Dostajemy na konsoli:

Compiling 1 source file to
/Users/piotrzalewski/NetBeansProjects/JavaApplication5/build/classes
compile:
/Users/piotrzalewski/NetBeansProjects/JavaApplication5/nbproject/build-impl.xml:725:
Unknown attributes [apgeneratedsrcdir, processorpath]
BUILD FAILED (total time: 5 seconds)

Zgłaszałem to jako buga na netbeans.org, został przypisany i trochę zignorowany :(. A szkoda, bo pisanie testów w Groovym jest łatwiejsze i wygodniejsze.

Postanowiłem więc mimo wsystko na tym posiedzieć i poszukać rozwiązania.
Są dwa problemy do rozwiązania:

  • 1. Nieścisłość w plikach anta.
  • 2. Wymuszenie kompilacji plików *.groovy przed testem i ich wykonanie w trakcie testu.

Dla piewszego problemu znalazłem japońskie rozwiązanie pod http://feather.cocolog-nifty.com/weblog/2010/06/netbeans69groov.html. Do pliku groovy-build.xml należy dodać definicje atrybutów:

<attribute default="${javac.processorpath}" name="processorpath"/>
            <attribute default="${build.generated.sources.dir}/ap-source-output" name="apgeneratedsrcdir"/>
w sekcji makrodefinicji dla "javac".

Drugi problem był łatwiejszy i rozwiązanie w bardziej ludzkim języku: http://charliesquires.wordpress.com/2009/08/30/running-groovy-tests-in-netbeans-6-7-1/ Podany kod należy wkleić między tagi w build.xml:

<target depends="init,compile-test,-pre-test-run" if="have.tests" name="-do-test-run">
        <j2seproject3:junit testincludes="**/*Test.class"/>
    </target>

    <target depends="init,compile-test-single,-pre-test-run-single" if="have.tests" name="-do-test-run-single">
        <fail unless="test.includes">Must select some files in the IDE or set test.includes</fail>
        <taskdef name="groovy" classname="org.codehaus.groovy.ant.Groovy" classpath="${javac.classpath}"/>
        <groovy>
            properties."test.includes.class" = properties."test.includes".split("\\.")[0] + ".class"
        </groovy>
        <j2seproject3:junit excludes="" includes="${test.includes.class}"/>
    </target>

    <target name="-init-macrodef-junit">
        <macrodef name="junit" uri="http://www.netbeans.org/ns/j2se-project/3">
            <attribute default="${includes}" name="includes"/>
            <attribute default="${excludes}" name="excludes"/>
            <attribute default="**" name="testincludes"/>
            <sequential>
                <junit dir="${work.dir}" errorproperty="tests.failed" failureproperty="tests.failed" fork="true" showoutput="true">
                    <batchtest todir="${build.test.results.dir}">
                        <fileset dir="${build.test.classes.dir}" excludes="@{excludes},${excludes}" includes="@{includes}">
                            <filename name="@{testincludes}"/>
                        </fileset>
                    </batchtest>
                    <classpath>
                        <path path="${run.test.classpath}"/>
                    </classpath>
                    <syspropertyset>
                        <propertyref prefix="test-sys-prop."/>
                        <mapper from="test-sys-prop.*" to="*" type="glob"/>
                    </syspropertyset>
                    <formatter type="brief" usefile="false"/>
                    <formatter type="xml"/>
                    <jvmarg line="${run.jvmargs}"/>
                </junit>
            </sequential>
        </macrodef>
    </target>
 
A w samym tagu project dodać:
xmlns:j2seproject3="http://www.netbeans.org/ns/j2se-project/3"

Uff - od razu łatwiej ;)

Kindle - internetowy tablet?

Z dużym zdziwieniem zaobserwowałem wczoraj, że mój Kindle bez problemu może wyświetlać strony www. Do tej pory w wersji International przeglądanie stron www było ograniczone do wikipedi (i to tylko mobilnej angielskiej) i sklepu Amazona. Bez problemu wszedłem na stronę swojego bloga, a także na mobilną (uproszczoną) wersje Gmaila.

Internet za darmo? Tak wygląda - bo za bezprzewodową łączność opartą na 3G nic się nie płaci. Kindle staje się bardzo ciekawym konkurentem dla brania laptopa na wakacje. Wady - przeglądarka Kindle jest bardzo uproszczona, nie wyświetla poprawnie wielu zaawansowanych styli css. Obsługa Javascriptu jakaś jest - ale fabrycznie jest wyłączona. Jednak wystarczające aby sprawdzić pocztę, jakieś informacje na blogach, czy gazetach w sieci.