मुख्य सामग्री पर जाएँ
CrossFly 100% ओपन सोर्सGitHub पर फ़ॉलो करें
CrossFlyCrossFly
शुरू करें
सभी उदाहरण
रेसिपीटेस्टिंग77 पंक्तियाँ · 1 फ़ाइलें

Making a screen testable

Tag anything a test must reach. Text breaks on rewording, class breaks on a second instance, index breaks on insertion — a tag breaks only when someone removes it.

यह क्या दिखाता है

Making a screen verifiable: tag what a test will point at, then read the tree back.

The button below prints this screen's structural portrait to the log — the same text a test compares against a committed baseline. Seeing it once is usually enough to understand why the portrait catches what assertions never think to ask.

अपनी मशीन पर चलाएँ

हर उदाहरण एक साधारण Window है, इसलिए लॉन्चर को सिर्फ़ उसका नाम चाहिए।

gradlew lwjgl3:run --args="classname dev.cf.recipe.R09Testable"
इसे बदलना

Java पहले से संकलित होता है, इसलिए ब्राउज़र आपके बदलाव को खुद दोबारा नहीं बना सकता — यहाँ दिखा कोड प्रकाशित होने से पहले TeaVM द्वारा JavaScript में बदला गया था। फ़ाइल को किसी प्रोजेक्ट में कॉपी कीजिए और वह चारों प्लेटफ़ॉर्म पर बिना बदलाव चलती है; ऊपर दी गई कमांड ही पूरी तैयारी है।

यहीं चल रहा हैCrossFly 0.1.32
ऐप शुरू हो रहा है…

TeaVM ने इसे JavaScript में संकलित किया — यह वही कोड है, उसका वीडियो नहीं। · सभी उदाहरण

यह क्या इस्तेमाल करता है

इस उदाहरण में छुए गए फ़्रेमवर्क टाइप। जिनमें लिंक है उनका संदर्भ पृष्ठ मौजूद है।

ButtonCardComponentDebugLabelScreenScreenReportStylesWidgets

सोर्स कोड

पूरा, बिना कटौती के। यह वही फ़ाइल है, उसका अंश नहीं।

कच्चा
dev/cf/recipe/R09Testable.java
package dev.cf.recipe;

import dev.cf.Tones;

import dev.crossfly.test.*;
import dev.crossfly.ui.*;
import dev.crossfly.ui.color.*;
import dev.crossfly.ui.graphics.*;
import dev.crossfly.ui.layout.*;
import dev.crossfly.ui.style.*;

import static dev.crossfly.ui.Widgets.*;

/**
 * Making a screen verifiable: tag what a test will point at, then read the tree back.
 *
 * <p>The button below prints this screen's structural portrait to the log — the same text a test
 * compares against a committed baseline. Seeing it once is usually enough to understand why the
 * portrait catches what assertions never think to ask.</p>
 */
public class R09Testable extends Recipe
{
   private int toques;
   private Label contador;

   public String title()
   {
      return "Making a screen testable";
   }

   public String note()
   {
      return "Tag anything a test must reach. Text breaks on rewording, class breaks on a second"
         + " instance, index breaks on insertion — a tag breaks only when someone removes it.";
   }

   public void build(Component body) throws Exception
   {
      contador = label(texto(), 2f, true, Tones.accent(), Position.START);
      contador.testTag("demo.counter");

      Button somar = Tones.action("Add one");
      somar.testTag("demo.add");
      somar.onAction(c ->
      {
         toques++;
         contador.setText(texto());
         contador.setValidLayout(false);
         Screen.repaint();
      });

      Button dump = new Button("Print the tree");
      dump.testTag("demo.dump");
      dump.onAction(c -> dev.crossfly.util.Debug.log(ScreenReport.tree(this, title())));

      body.add(LAY_AUTO, outgap(contador, 0, 0, 0, .8f));
      body.add(LAY_AUTO, outgap(somar, 0, 0, 0, .6f));
      body.add(LAY_AUTO, outgap(dump, 0, 0, 0, 1f));

      // The three lines are code, so they get a surface of their own rather than sitting loose
      // in the page looking like more prose.
      Card codigo = Tones.card(Tones.support());
      codigo.add(LAY_AUTO, Tones.head(0xE86F, "From a TestCase, that is", Tones.support()));
      for (String l : new String[] { "clickTag(\"demo.add\");",
         "verifyTag(\"demo.counter\").text(\"1 tap\");",
         "new ScreenReport(this).checkBaseline(dir, \"demo\", false);" })
         codigo.add(LAY_AUTO, outgap(label(l, 1f, false, Styles.textColor, Position.START),
            0, 0, 0, .25f));
      body.add(LAY_AUTO, codigo);
   }

   private String texto()
   {
      return toques + (toques == 1 ? " tap" : " taps");
   }
}
एआई सहायक के लिए

इस पृष्ठ के मशीन-पठनीय रूप, ताकि मॉडल API का अनुमान लगाने के बजाय उदाहरण पढ़ सके।

यह उदाहरण, JSON मेंयह उदाहरण, Markdown में
पिछलाReordering a listअगलाA form that fights back