本文整理汇总了Java中osmo.common.TestUtils类的典型用法代码示例。如果您正苦于以下问题:Java TestUtils类的具体用法?Java TestUtils怎么用?Java TestUtils使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
TestUtils类属于osmo.common包,在下文中一共展示了TestUtils类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: schemaSNMPFloatToTable
import osmo.common.TestUtils; //导入依赖的package包/类
@Test
public void schemaSNMPFloatToTable() {
Config.cassandraKeySpace = "test_ks";
SchemaRepository repo = new SchemaRepository();
Collection<Schema> schemas = repo.getSchemas();
Schema snmpFloat = null;
for (Schema schema : schemas) {
String name = schema.getName();
if (name.equals("SNMPFloat")) {
snmpFloat = schema;
break;
}
}
String table = CassandaAvroConsumer.tableFor(snmpFloat);
String expected = TestUtils.getResource(CassandraAvroTests.class, "expected_snmpfloat_table.txt");
assertEquals(table, expected, "Generated table for SNMPFloat schema");
}
示例2: insertForSNMPFloat
import osmo.common.TestUtils; //导入依赖的package包/类
@Test
public void insertForSNMPFloat() {
Config.cassandraKeySpace = "test_ks";
SchemaRepository repo = new SchemaRepository();
Collection<Schema> schemas = repo.getSchemas();
Schema snmpFloat = null;
for (Schema schema : schemas) {
String name = schema.getName();
if (name.equals("SNMPFloat")) {
snmpFloat = schema;
break;
}
}
String table = CassandaAvroConsumer.insertFor(snmpFloat);
String expected = TestUtils.getResource(CassandraAvroTests.class, "expected_snmpfloat_insert.txt");
assertEquals(table, expected, "Generated insert for SNMPFloat schema");
}
示例3: main
import osmo.common.TestUtils; //导入依赖的package包/类
public static void main(String[] args) {
long seed = Long.parseLong(args[0]);
OSMOConfiguration oc = new OSMOConfiguration();
oc.setFactory(new CalendarFactory());
EndCondition ec1 = new LengthProbability(1, 0.5);
EndCondition ec2 = new LengthProbability(10, 0.2);
EndCondition ec3 = new LengthProbability(50, 0.5);
WeightedEndConditionSet set = new WeightedEndConditionSet(10, ec1, 100, ec2);
set.addEndCondition(20, ec3);
oc.setTestEndCondition(set);
ScoreConfiguration sc = new ScoreConfiguration();
MultiGreedy greedy = new MultiGreedy(oc, sc, seed);
greedy.setTimeout(10);
List<TestCase> tests = greedy.search();
int i = 1;
for (TestCase test : tests) {
TestUtils.write((String)test.getAttribute("script"), "calendar-example/test"+i+".html");
i++;
}
HTMLCoverageReporter html = new HTMLCoverageReporter(greedy.getFinalCoverage(), tests, greedy.getFsm());
String report = html.getTraceabilityMatrix();
TestUtils.write(report, "calendar-example/coverage.html");
}
示例4: createScoreReport
import osmo.common.TestUtils; //导入依赖的package包/类
/**
* Creates a report for exploration/generation.
* Prints information such as covered elements, achieved score, used generation parameters.
*/
private void createScoreReport() {
boolean printAll = config.isPrintAll();
Map<String, Collection<String>> possibleValues = algorithm.getPossibleValues();
Collection<String> possibleStepPairs = algorithm.getPossibleStepPairs();
Map<String, Collection<String>> possibleStatePairs = algorithm.getPossibleStatePairs();
Map<String, Collection<String>> possibleStates = algorithm.getPossibleStates();
List<TestCase> allTests = osmo.getSuite().getAllTestCases();
TestCoverage tc = new TestCoverage(allTests);
ScoreCalculator sc = new ScoreCalculator(config);
System.out.println("Generated " + allTests.size() + " tests. Achieved score " + sc.calculateScore(tc));
CSVCoverageReport report = new CSVCoverageReport(sc);
String summary = "summary\n";
summary += tc.coverageString(osmo.getFsm(), possibleStepPairs, possibleValues, possibleStates, possibleStatePairs, printAll);
System.out.println(summary);
report.process(allTests);
String totalCsv = report.report();
totalCsv += summary + "\n";
TestUtils.write(totalCsv, createFullReportPath());
}
示例5: writeFinalReport
import osmo.common.TestUtils; //导入依赖的package包/类
/**
* Write the final report for the overall optimized test set.
* Goes into "osmo-output/greedy-<seed>/final-scores.csv" file.
*
* @param cases The final set of generated tests.
* @param seed The seed used in configuring all the optimizers. Shown in report.
*/
private void writeFinalReport(List<TestCase> cases, long seed) {
String summary = "summary\n";
summary += "tests: "+cases.size()+"\n";
CSVCoverageReport report = new CSVCoverageReport(calculator);
report.process(cases);
finalCoverage = new TestCoverage(cases);
summary += finalCoverage.coverageString(fsm, possiblePairs, null, null, null, false);
String totalCsv = report.report();
totalCsv += summary + "\n";
String filename = createFinalReportPath();
TestUtils.write(totalCsv, filename);
}
示例6: writeReports
import osmo.common.TestUtils; //导入依赖的package包/类
/**
* Write the d reports for found steps and invariants.
*
* @param allSteps All steps in test model, used in test or not.
* @param state End state for reduction to report.
*/
private void writeReports(List<String> allSteps, ReducerState state) {
//first we find all invariants and write the basic report on those
Analyzer analyzer = new Analyzer(allSteps, state);
analyzer.analyze();
analyzer.writeReport("reducer-final");
//then we write the traces for best tests, limiting to max of 100 traces
List<TestCase> tests = state.getTests();
List<TestCase> traced = new ArrayList<>();
int i = 1;
for (TestCase test : tests) {
i++;
//only print max of 100 traces
if (i > 100) break;
traced.add(test);
}
String filename = analyzer.getPath() + "final-tests";
OSMOTester.writeTrace(filename, traced, config.getSeed(), osmoConfig);
String filename2 = analyzer.getPath() + "final-fuzz-times.csv";
TestUtils.write(state.getFinalFuzzTimes(), filename2);
}
示例7: greedy
import osmo.common.TestUtils; //导入依赖的package包/类
@Test
public void greedy() {
OSMOConfiguration oc = new OSMOConfiguration();
oc.setTestEndCondition(new LengthProbability(10, 20, 0.2d));
oc.setFactory(models -> models.add(new VendingMachine()));
ScoreConfiguration config = new ScoreConfiguration();
config.setLengthWeight(0);
MultiGreedy mg = new MultiGreedy(oc, config, 111, 1);
mg.setPopulationSize(500);
mg.setMaxIterations(5);
List<TestCase> tests = mg.search();
int i = 1;
for (TestCase test : tests) {
TestUtils.write(test.getAttribute("script").toString(), "example/tests/"+test.getName()+".txt");
i++;
}
TestCoverage coverage = mg.getFinalCoverage();
HTMLCoverageReporter html = new HTMLCoverageReporter(coverage, tests, mg.getFsm());
String matrix = html.getTraceabilityMatrix();
TestUtils.write(matrix, "example/example_report.html");
}
示例8: issue32
import osmo.common.TestUtils; //导入依赖的package包/类
@Test
public void issue32() {
OSMOTester tester = new OSMOTester();
tester.setTestEndCondition(new Length(5));
tester.setSuiteEndCondition(new Length(5));
tester.setAlgorithm(new WeightedBalancingAlgorithm());
ByteArrayOutputStream bos = new ByteArrayOutputStream();
PrintStream ps = new PrintStream(bos);
tester.setModelFactory(new MyModelFactory(ps));
tester.generate(333);
String expected = TestUtils.getResource(Issue32to36.class, "expected/issue32.txt");
String actual = bos.toString();
actual = unifyLineSeparators(actual, "\n");
expected = unifyLineSeparators(expected, "\n");
assertEquals("WeightedBalancing should not interfere with guards", expected, actual);
}
示例9: issue33
import osmo.common.TestUtils; //导入依赖的package包/类
@Test
public void issue33() throws IOException {
OSMOTester tester = new OSMOTester();
tester.setTestEndCondition(new Length(5));
tester.setSuiteEndCondition(new Length(5));
tester.setAlgorithm(new WeightedBalancingAlgorithm());
tester.setModelFactory(new MyModelFactory(NullPrintStream.stream));
tester.generate(333);
TestSuite suite = tester.getSuite();
FSM fsm = tester.getFsm();
HTMLCoverageReporter reporter = new HTMLCoverageReporter(suite.getCoverage(), suite.getAllTestCases(), fsm);
String matrix = reporter.getTraceabilityMatrix();
String expected = TestUtils.getResource(Issue32to36.class, "expected/issue33.txt");
matrix = unifyLineSeparators(matrix, "\n");
expected = unifyLineSeparators(expected, "\n");
assertEquals("Reporting of test trace order", expected, matrix);
}
示例10: issue34
import osmo.common.TestUtils; //导入依赖的package包/类
@Test
public void issue34() throws Exception {
OSMOTester tester = new OSMOTester();
tester.getConfig().setDataTraceRequested(true);
tester.setTestEndCondition(new Length(5));
tester.setSuiteEndCondition(new Length(5));
tester.setAlgorithm(new WeightedBalancingAlgorithm());
tester.setModelFactory(new MyModelFactory(NullPrintStream.stream));
tester.generate(333);
TestSuite suite = tester.getSuite();
TraceReportWriter tracer = new TraceReportWriter();
String report = tracer.createReport(suite.getAllTestCases());
String expected = TestUtils.getResource(Issue32to36.class, "expected/issue34.txt");
report = unifyLineSeparators(report, "\n");
expected = unifyLineSeparators(expected, "\n");
assertEquals("Reporting of test trace order", expected, report);
}
示例11: failureCollector
import osmo.common.TestUtils; //导入依赖的package包/类
@Test
public void failureCollector() {
ErrorModelProbability model = new ErrorModelProbability();
OSMOTester tester = new OSMOTester();
Length length = new Length(10);
tester.setSuiteEndCondition(length);
tester.setTestEndCondition(length);
OSMOConfiguration config = tester.getConfig();
config.setKeepTests(false);
config.setStopGenerationOnError(false);
config.setStopTestOnError(true);
FailureCollector collector = new FailureCollector();
config.addListener(collector);
tester.addModelObject(model);
tester.generate(1);
TestSuite suite = tester.getSuite();
List<TestCase> tests = suite.getAllTestCases();
assertEquals("Number of tests in generator", 0, tests.size());
assertEquals("Number of collected failures", 7, collector.getFailed().size());
final String listenerFolder = "osmo-output/listener";
TestUtils.recursiveDelete(listenerFolder);
collector.writeTrace(listenerFolder);
TestLoader loader = new TestLoader();
List<TestScript> scripts = loader.loadTests(listenerFolder);
assertEquals("Number of loaded tests", 7, scripts.size());
}
示例12: generate4
import osmo.common.TestUtils; //导入依赖的package包/类
@Test
public void generate4() throws Exception {
Thread.sleep(100);
MultiOSMO mosmo = new MultiOSMO(4);
OSMOConfiguration config = mosmo.getConfig();
config.setSequenceTraceRequested(true);
config.setFactory(new MyModelFactory());
config.setTestEndCondition(new Length(10));
config.setSuiteEndCondition(new Time(2));
mosmo.generate(new Time(1), 444);
// List<String> reports = TestUtils.listFiles(OUTPUT_FOLDER, ".csv", false);
// assertEquals("Number of reports generated", 4, reports.size());
List<String> traces = TestUtils.listFiles(OUTPUT_FOLDER, ".html", false);
assertEquals("Number of HTML traces generated", 4, traces.size());
List<String> xmls = TestUtils.listFiles(OUTPUT_FOLDER, ".xml", false);
assertEquals("Number of XML traces generated", 4, xmls.size());
}
示例13: twoVariablesTwoTestsTwoSteps
import osmo.common.TestUtils; //导入依赖的package包/类
@Test
public void twoVariablesTwoTestsTwoSteps() {
RFScripter scripter = new RFScripter(2);
scripter.setTestLibrary("SeleniumLibrary");
scripter.addVariable("var1", "hello");
scripter.addVariable("var2", "world");
scripter.startTest("test1");
scripter.addStep("step1-1", new RFParameter("s1-1 p1"), new RFParameter("s1-1 p2"));
scripter.addStep("step1-2", new RFParameter("s1-2 p1"), new RFParameter("s1-2 p2"));
scripter.startTest("test2");
scripter.addStep("step2-1", new RFParameter("s2-1 p1"), new RFParameter("s2-1 p2"));
scripter.addStep("step2-2", new RFParameter("s2-2 p1"), new RFParameter("s2-2 p2"));
String script = scripter.createScript();
script = unifyLineSeparators(script, "\n");
String expected = TestUtils.getResource(RobotFrameworkTests.class, "expected1.html");
expected = unifyLineSeparators(expected, "\n");
assertEquals("Generated script", expected, script);
}
示例14: calculatorOptimization
import osmo.common.TestUtils; //导入依赖的package包/类
@Test
public void calculatorOptimization() throws Exception {
OSMOConfiguration oc = new OSMOConfiguration();
oc.setTestEndCondition(new LengthProbability(1, 5, 0.2d));
oc.setFactory(new MyModelFactory());
oc.setTrackOptions(true);
ScoreConfiguration config = new ScoreConfiguration();
config.setLengthWeight(0);
MultiGreedy multiGreedy = new MultiGreedy(oc, config, 111, 5);
List<TestCase> tests = multiGreedy.search();
assertEquals("Number of tests from MultiGreedy", 3, tests.size());
assertEquals("MultiGreedy test1", "TestCase:[start, increase, decrease, increase, increase]", tests.get(0).toString());
assertEquals("MultiGreedy test2", "TestCase:[start, increase, increase, decrease, decrease]", tests.get(1).toString());
assertEquals("MultiGreedy test3", "TestCase:[start, increase, increase, increase, increase]", tests.get(2).toString());
String report = TestUtils.readFile(multiGreedy.createFinalReportPath(), "UTF8");
String expected = TestUtils.getResource(GreedyTests.class, "expected-multigreedy.txt");
assertEquals("Multi-Greedy report", expected, report);
}
示例15: generation
import osmo.common.TestUtils; //导入依赖的package包/类
@Test
public void generation() throws Exception {
ScoreConfiguration config = new ScoreConfiguration();
config.setLengthWeight(0);
oc.setTestEndCondition(new LengthProbability(1, 5, 0.1d));
oc.setTrackOptions(true);
ReflectiveModelFactory factory = new ReflectiveModelFactory(CalculatorModel.class);
oc.setFactory(factory);
GreedyOptimizer optimizer = new GreedyOptimizer(oc, config);
GenerationResults results = optimizer.search(8);
List<TestCase> tests = results.getTests();
assertEquals("Number of tests from greedy", 3, tests.size());
assertEquals("First test from greedy", "[start, increase, decrease, increase, increase]", tests.get(0).getAllStepNames().toString());
assertEquals("Second test from greedy", "[start, increase, increase, decrease, decrease]", tests.get(1).getAllStepNames().toString());
assertEquals("Third test from greedy", "[start, increase, increase, increase, increase]", tests.get(2).getAllStepNames().toString());
// assertEquals("Output report from greedy", "", TestUtils.getOutput());
String report = TestUtils.readFile(optimizer.createReportPath(), "UTF8");
String expected = TestUtils.getResource(GreedyTests.class, "expected-greedy.txt");
assertEquals("Greedy report", expected, report);
}