0

私の clojure プロジェクトでは、gen-classコマンドを使用していくつかの Java クラスを作成しました。彼らは[extractor.yaml YAMLExtractor YAMLExtractorFactory]です。これらのクラスに対して単体テストをビルドしたかったのですが、java.lang.ClassNotFoundException: extractor.yaml.YAMLExtractorテストを実行するとエラーが発生しました。

エラーの原因となるファイル: yaml_extrator_factory.clj

(ns extractor.yaml-extractor-factory
  (:gen-class :name extractor.yaml.YAMLExtractorFactory
              :extends org.apache.any23.extractor.SimpleExtractorFactory
              :implements [org.apache.any23.extractor.ExtractorFactory]
              :init init
              :constructors {[] [String org.apache.any23.rdf.Prefixes java.util.Collection String]}
              :main false)
  (:require [extractor.yaml-extractor])
  (:import [extractor.yaml YAMLExtractor]
           [org.apache.any23.rdf Prefixes]
           [org.apache.any23.extractor SimpleExtractorFactory ExtractorFactory Extractor ExtractionContext ]))

エラーは、テスト中にのみ発生します。プロジェクト全体がエラーなしで AOT コンパイル可能であり、jar ファイルをビルドしても問題ありません。

テストsimple.cljには head が含まれています:

(ns extractor.simple
    (:use [clojure.tools.logging :as log]
          [clojure.java.io :as jio]
          [clojure.test :as test])
    (:require [extractor.yaml-extractor-factory])
    (:import [java.util Arrays]
             [extractor.yaml.YAMLExtractorFactory]))

そして、どのクラスが CLASSPATH を出力するかをテストします。yaml-extractor-factory使用されませんでした。テストは次のコマンドで実行されます:

boot aot -a update-classpath run-test -t extractor.simple

ここで、タスクupdate-classpathがクラスパスに追加(get-env :directories)され、run-testがテストを実行します。run-test通常の clojure コードで問題なく動作します。

run-testは、次の内容の私のタスクです。

(deftask run-test "Run unit tests"
  [t test-name NAME str "Test to execute. Run all tests if not given."]

  (require '[extractor.simple])
  (with-pass-thru [_]
    (if (nil? test-name)
      (do
        (util/info "Run all tests")
        (test/run-all-tests))
      (do
        (util/info (format "Run test: %s" (:test-name *opts*)))
        (test/run-tests (symbol (:test-name *opts*)))
        ))))
4

0 に答える 0