简体   繁体   English

如何指定要测试的实现

[英]How to specify which implementation to test

My professor has given us an assignment to implement two interfaces and he has built a tester for each interface. 我的教授给我们分配了实现两个接口的任务,他为每个接口构建了一个测试器。 I have written my code, but when I run the testers I always get stuck at the line to specify which implementation to test. 我已经编写了代码,但是当我运行测试仪时,我总是束手无策地指定要测试的实现。 Here is a link to the website so you can view the testers. 这是网站的链接,因此您可以查看测试人员。 I have no idea what to do. 我不知道该怎么做。 If I need to provide anymore information let me know. 如果我需要提供更多信息,请告诉我。

https://www.cct.lsu.edu/~sbrandt/csc1351/06/1351-merge-sort.php https://www.cct.lsu.edu/~sbrandt/csc1351/06/1351-merge-sort.php

In MTester.java and MTesterL.java, you can see the line Class<?> c = Class.forName(args[0]); 在MTester.java和MTesterL.java中,您可以看到行Class<?> c = Class.forName(args[0]); ;。 . That means that you need to pass to the java test program the name of your Implementation. 这意味着您需要将实现的名称传递给Java测试程序。 Look how to pass args to main here: https://stackoverflow.com/a/19648592/5947244 在这里查看如何将args传递给main: https : //stackoverflow.com/a/19648592/5947244

When I understand your problem and the tester code currently, you need to pass the full class name of your implementation as the command line argument of the program. 当我了解您的问题和当前的测试人员代码时,您需要将实现的完整类名作为程序的命令行参数传递。

Assuming all the source files are the current directory and all are in the default package (have no package declared on top) and your implementation is in a file MSorter.java , the command line could look like: 假设所有源文件都是当前目录,并且所有文件都位于默认包中(没有在顶部声明任何包),并且您的实现位于文件MSorter.java ,命令行可能类似于:

> javac -cp . *.java
> java -cp . Tester MSorter
> java -cp . MTesterL MSorterL

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM