JavaRush
AI Academy
new
Promotion
Learning
Courses
Tasks
Quizzes
Games
Help
Schedule of nudges
Internship
Community
Users
Forum
Chat
Articles
Activities
Reviews
Subscriptions
Light theme

Lectures

  • Reviews
  • About us
  • CS50
Start
Start learning
Start learning
  • My progress
  • Courses
  • Quest map
  • Lectures
  • Injecting io.Writer/ io.Reader instead of direct stdout/stdin

    Go SELF
    53 level,0 lecture
    We break down why, in a CLI, it is better not to write directly to os.Stdout and not to read from os.Stdin, but to inject dependencies via io.Writer/ io.Reader. We design a command contract Run(...) that returns an exit code, keep main thin, separate stdout/stderr, and configure flag.FlagSet output via SetOutput. As a result, the CLI becomes predictable and easy to test without “intercepting” global I/O.
    Open
  • Table-driven CLI tests: args → exit code → output

    Go SELF
    53 level,1 lecture
    We break down how to test a CLI in Go in a table-driven style: turning a command run into a verifiable contract args → exit code + stdout/ stderr, capturing output via bytes.Buffer, feeding stdin via strings.NewReader, adding stdin support to cases, using t.Run and a helper with t.Helper(), and also discussing when it’s better to assert whole messages vs. fragments ( strings.Contains).
    Open
  • Golden files — store expected output in files

    Go SELF
    53 level,2 lecture
    We break down the golden files approach for testing CLI text output in Go: where to store snapshots ( testdata/), how to write helpers readGolden/ writeGolden, how to safely update expectations via the -update flag ( go test), and which typical mistakes destroy trust in these tests (non-determinism, mixing stdout/ stderr, “invisible” diffs forever due to the final newline).
    Open
  • Test stabilization: freezing time

    Go SELF
    53 level,3 lecture
    We break down why CLI tests are “sometimes red” and turn them deterministic: we extract time via a dependency Clock/ FakeClock instead of calling time.Now() directly, lock down the time format ( UTC() + RFC3339), and also stabilize output order by sorting tasks (instead of a random range over a map). At the end: how this helps golden tests, and which mistakes most often break stability.
    Open
  • Filesystem testing: t.TempDir() and fstest.MapFS

    Go SELF
    53 level,4 lecture
    We break down why tests tied to “real” files next to the project fail in CI and on other machines, and how to isolate the environment. In practice, we use t.TempDir() for honest on-disk file scenarios and fstest.MapFS together with io/fs for fast unit tests without I/O. Plus: path nuances, verifying file contents, and common mistakes.
    Open
Learn
  • Registration
  • Java course
  • Help with tasks
  • Pricing
Community
  • Users
  • Articles
  • Forum
  • Chat
  • Activities
Company
  • About us
  • Contacts
  • Reviews
  • FAQ
  • Support
JavaRushJavaRush — is an interactive online course for learning Java programming from scratch. It contains 1200 practical tasks with one-click solution checking, the necessary minimum of theory on Java basics, and motivating features that help you complete the course: games, quizzes, interesting projects and articles on effective learning and the career of a Java developer.
Follow us
Язык интерфейса
Русский
English
Українська
"Programmers are not born" © 2026 JavaRush
MastercardVisa
"Programmers are not born" © 2026 JavaRush